B4J Question Warning #22 message

Daestrum

Expert
Licensed User
Longtime User
Should I be concerned at this warning, I am passing an Integer to a sub that expects a javaobject.

I thought a javaobject could take any type of variable.

B4X:
...
Log(Integer_toHexString(1,99)  << warning on this line  "Types do not match. (warning #22)"
...

'++++++++++++++++++++++++
'++ AutoGenerated Code ++
'++++++++++++++++++++++++
' Argument is : int
Sub Integer_toHexString(ob As JavaObject, arg As Int) As String
	Return ob.RunMethod("toHexString",Array(arg))
End Sub
 

Daestrum

Expert
Licensed User
Longtime User
I do normally, but I am testing some code that generates the entire sub to execute javaobject.runmethod for any class in the java libraries.

(I picked the hextostring as I know what I should get back, all I had to do was type 'Integer', then selected java.lang.Integer, then selected toHexString(int) and the code was produced for me).

So can I ignore the warning as the code seems to run ok, but wanted to check.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Should I be concerned at this warning, I am passing an Integer to a sub that expects a javaobject.

I thought a javaobject could take any type of variable.

B4X:
...
Log(Integer_toHexString(1,99)  << warning on this line  "Types do not match. (warning #22)"
...

'++++++++++++++++++++++++
'++ AutoGenerated Code ++
'++++++++++++++++++++++++
' Argument is : int
Sub Integer_toHexString(ob As JavaObject, arg As Int) As String
    Return ob.RunMethod("toHexString",Array(arg))
End Sub

You are passing 1 as java object (on which you run a method)
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Because Java is nice - in that case it just uses the class ie Integer for the call as that what it expects to be there

In 'pure' Java you would write Integer.toHexString(99);

I would guess the generated java for the Sub would be like
B4X:
public String name_of_the_sub(Object o, Integer arg){
Class<?> c = o.getClass();
...
return c.toHexString(arg);
}
 
Last edited:
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Because Java is nice - in that case it just uses the class ie Integer for the call as that what it expects to be there

In 'pure' Java you would write Integer.toHexString(99);

I would guess the generated java for the Sub would be like
B4X:
public String name_of_the_sub(Object o, Integer arg){
Class<?> c = o.getClass();
...
return c.toHexString(arg);
}


Now I remember that something like this exists in .Net too (after all, coincidentally, VB.Net, C#, etc. followed Java); but I don't entered into these "subtleties" :)
 
Upvote 0
Top