B4J Code Snippet Initializing JavaObject

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:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…