B4J Code Snippet Initializing JavaObject

Similar threads

B4J Code Snippet Redirect the output to a file
B4A Code Snippet [B4X] Round clipping panel
B4J Tutorial jPOI to the rescue
B4J Code Snippet Metro Style with JMetro
B4J Tutorial [Server] Screen capture server

Daestrum

Well-Known Member
Licensed User
I often wished the following code was valid
B4X:
Dim someVar as JavaObject = someVar.InitializeNewInstance("some.java.class",null)
but alas, someVar doesn't exist on the right side until the dim statement is executed
so we have to use
B4X:
Dim someVar as JavaObject
someVar.InitializeNewInstance("some.java.class",null)
but …..
if you add this tiny method
B4X:
Sub New(javaClass as String, Values() as Object) As JavaObject
Dim Jo as JavaObject
Return Jo.InitiallizeNewInstance(javaClass,values)
End Sub
Now you can have
B4X:
Dim someVar As JavaObject = New("some.java.class",null)
 
Last edited:
Top