One thing I miss in B4A is the ability to add constructors and destructors on classes. We have initialize, but it's kind of a halfway solution for constructors.
With full support for these, one could do such things as:
Then, somewhere else, do stuff like:
Which, in this simple case would generate this log:
100,200
200,300
In other words, the constructor runs automatically when the object is created (which also means that any arguments in the constructor are enforced by the compiler), and the destructor when it's destroyed, allowing stuff like clean up or saving state.
With full support for these, one could do such things as:
B4X:
Sub Class_Globals
Dim x As Int
Dim y As Int
End Sub
Public Sub Initialize(newx As Int, newy As Int)
x=newx
y=newy
End Sub
Public Sub Unload()
Log(X & "," & Y)
End Sub
Then, somewhere else, do stuff like:
B4X:
Dim Position As cPosition(100,200)
Dim Position As cPosition(200,300)
Position=Null
Which, in this simple case would generate this log:
100,200
200,300
In other words, the constructor runs automatically when the object is created (which also means that any arguments in the constructor are enforced by the compiler), and the destructor when it's destroyed, allowing stuff like clean up or saving state.