B4A Classes & Functions

Vircop

Member
Licensed User
Longtime User
Hello,

short question:

How do i write the following java code in B4A? (please notice that it has the same function name but with different parameters within one class)

B4X:
public class whatever
{

static int make( int r, int g, int b, int a )
{
 ... function code...
}

static int make( int r, int g, int b )
{
 ... function code again...
}

} // end of class

B4A complains that it hase double function names - but in java that works.

Thanks for any help!
 

Vircop

Member
Licensed User
Longtime User
As for now i made a function called "make4" and another "make3" to have a workaround for overloaded functions. Just wanted to know if i'm missing something. If that is not implemented is that feature planned?
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
I believe this is known as function overloading and is not possible within b4a.

Could you not create the single function with all params and pass Null when they are not required. Then check with function if they are Null.
 
Upvote 0

Vircop

Member
Licensed User
Longtime User
I believe this is known as function overloading and is not possible within b4a.

Yes, it's called overloading. It's basically usefull if you want to add let's say 2 values (as integers) and somewhere else you need to add two floats. So you don't need to keep track of 2 different names (such as AddInt and AddFloat) you could just use Add no matter what you pass the function will work. (because if you pass float it will use the float function to add and therefore you don't lose the result because it's not cast to an int)
 
Upvote 0
Top