V Vircop Member Licensed User Longtime User Dec 1, 2012 #1 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) Code: Copy 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!
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) Code: Copy 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!
V Vircop Member Licensed User Longtime User Dec 1, 2012 #2 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
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?
barx Well-Known Member Licensed User Longtime User Dec 1, 2012 #3 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
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.
V Vircop Member Licensed User Longtime User Dec 1, 2012 #4 barx said: I believe this is known as function overloading and is not possible within b4a. Click to expand... 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
barx said: I believe this is known as function overloading and is not possible within b4a. Click to expand... 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)