Java Question getXXX vs getXXX(params)

tchart

Well-Known Member
Licensed User
Longtime User
A question regarding Java libraries which Ive never been able to figure out.

If I have this code

B4X:
public String getManufacturer()
{
    return os.getManufacturer();
}

In B4X I see the method as "Manufacturer as String (read only)"

However if I have this code;

B4X:
public String getManufacturer(String param)
{
    return os.getManufacturer();
}

In B4X I see the method as "getManufacturer(String param) as String"

Is there any way to get the second one to show up as a Manufacturer (i.e remove the get when using parameters)?
 

barx

Well-Known Member
Licensed User
Longtime User
Why would you want to give a parameter? Please explain your case a little better and it may make more sense.
Methods that start with get or set and have no parameters are indeed converted to a property. They are known as getters and setters. It basically acts as though you are accessing a property of a class directly, but gives you a chance to add some middle-man code for things like validation, etc
 

tchart

Well-Known Member
Licensed User
Longtime User
Why would you want to give a parameter? Please explain your case a little better and it may make more sense.
Methods that start with get or set and have no parameters are indeed converted to a property. They are known as getters and setters. It basically acts as though you are accessing a property of a class directly, but gives you a chance to add some middle-man code for things like validation, etc

That was just an example. The library I am writing has many methods, some take a parameter some don't.

It just inconsistent when I use the library in B4X as some methods show up with getXXX and some don't (because some require a parameter).

So when looking at the methods available the list is all mixed up...
 

DonManfred

Expert
Licensed User
Longtime User
It just inconsistent when I use the library in B4X as some methods show up with getXXX and some don't (because some require a parameter).
you can write helpermethods for such cases. something like

Java:
public String getAuthor(){
    return obj.getSomethingwithparameters("Author");
}
 
Top