Java Question Create static libraries

corwin42

Expert
Licensed User
Longtime User
With B4A 2.50 it is possible to compile code modules to a library and the methods in it can be called in a static way (you don't need to Dim an object to call these methods)

I think this is possible because of the class declaration in the xml:

<class b4a_type="StaticCode">

Is this supported somehow by the BADoclet.class or will there be a newer version of it so we can create static methods for our own libraries and we don't need to Dim a dummy object for calling such methods?
 

corwin42

Expert
Licensed User
Longtime User
I think the only advantage would be that you don't need the Dim for the instance variable.

I just wondered if it is possible because I created a class with only static methods in it and there is no possibility to call them "the static way" but it is possible when you create a library from a code module.
 

zolive33

Active Member
Licensed User
Longtime User

Yes it's possible (I just tried). Under Eclipse, in xml file, you have to modify the definition of the class by adding b4a_type="StaticCode". I think that all objects must static.

:sign0013: I'm not good in english!

Example :

ZOTest.java
B4X:
import anywheresoftware.b4a.BA.ShortName;

@ShortName("ZOTest")

public class ZOTest
{
  public static final int Var_A = 1;
  public static final int Var_B = 2;
}

MyLib.xml
B4X:
<class b4a_type="StaticCode">
        <name>zolive33.b4a.Library.MyLib.ZOTest</name>
        <shortname>ZOTest</shortname>
        <owner>process</owner>
        <field>
            <name>Var_B</name>
            <comment></comment>
            <returntype>int</returntype>
        </field>
        <field>
            <name>Var_A</name>
            <comment></comment>
            <returntype>int</returntype>
        </field>
    </class>

B4A :
B4X:
Msgbox ("test : " & ZOTest.Var_B ,"OK")
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…