It would be very useful to have the concept of (functional) overloading also in b4a.
Example for a sub, that handles different datatypes in a different way:
Example for a sub with optional parameter:
As Java already knows this concept (even polyphormism), it should not be too difficult to realize it - I hope.
And it's fully backward compatible with already existing code.
Example for a sub, that handles different datatypes in a different way:
B4X:
Sub MyLog(i As Int)
Log("Int: " & i)
End Sub
Sub MyLog(f As Float)
Log("Float: " & f)
End Sub
'...
Sub MyLog(a() As Object)
Dim i As Long
Log("Array: [")
For i = 0 To a.Length - 1
MyLog(a(i))
Log(", ")
Next'i
Log("]")
End Sub
Example for a sub with optional parameter:
B4X:
Sub InStr(str As String, pattern As String, iStart As Int) As Int
'Search a substring, starting at iStart:
'...
End Sub
Sub InStr(str As String, pattern As String) As Int
'Search a substring, starting left as default:
Return InStr(str, pattern, 0)
End Sub
As Java already knows this concept (even polyphormism), it should not be too difficult to realize it - I hope.
And it's fully backward compatible with already existing code.
Last edited: