Chris Lee Member Licensed User Jul 2, 2019 #1 When calling GetType on modules such as the Main module the value returned is 'java.lang.class'. Does anyone know a way of obtaining more information about the class such as it's name?
When calling GetType on modules such as the Main module the value returned is 'java.lang.class'. Does anyone know a way of obtaining more information about the class such as it's name?
stevel05 Expert Licensed User Longtime User Jul 2, 2019 #2 Will this suffice? Code: Log(Me) Returns : "class b4j.example.main" on the main module Last edited: Jul 2, 2019 Upvote 0
EnriqueGonzalez Expert Licensed User Longtime User Jul 3, 2019 #3 stevel05 said: Will this suffice? Code: Log(Me) Returns : "class b4j.example.main" on the main module Click to expand... but Log does not return a value, it will be only for debugging pourposes, but if Log actually calls the .toString function then i would add. Code: sub asJo as JavaObject return me end sub asjo.runmethod("toString",null) i wrote it without testing. Upvote 0
stevel05 said: Will this suffice? Code: Log(Me) Returns : "class b4j.example.main" on the main module Click to expand... but Log does not return a value, it will be only for debugging pourposes, but if Log actually calls the .toString function then i would add. Code: sub asJo as JavaObject return me end sub asjo.runmethod("toString",null) i wrote it without testing.
Erel B4X founder Staff member Licensed User Longtime User Jul 3, 2019 #4 You probably should use classes instead of static code modules. Upvote 0
stevel05 Expert Licensed User Longtime User Jul 3, 2019 #5 Enrique Gonzalez R said: Code: sub asJo as JavaObject return me end sub asjo.runmethod("toString",null) Click to expand... or Code: Dim S As String = Me Log(S) Upvote 0
Enrique Gonzalez R said: Code: sub asJo as JavaObject return me end sub asjo.runmethod("toString",null) Click to expand... or Code: Dim S As String = Me Log(S)
Chris Lee Member Licensed User Jul 4, 2019 #6 stevel05 said: or Code: Dim S As String = Me Log(S) Click to expand... The conversion to a string seems to be simplest approach. Thanks for this and the other replies. Upvote 0
stevel05 said: or Code: Dim S As String = Me Log(S) Click to expand... The conversion to a string seems to be simplest approach. Thanks for this and the other replies.
LucaMs Expert Licensed User Longtime User Jul 5, 2019 #7 I'm lost, here. I suppose you want to know the name of your custom class by getting it from an instance of your class. Simply using the suggestions, I get useless values: Code: #Region PROPERTIES Public Sub getClassType As String Dim s As String = Me Return s End Sub Using the property above I get this stuff: Class Type: [fx=anywheresoftware.b4j.objects.JFX@1a579872, mvalue=, main=null[/COLOR] I found answers on stackoverflow.com, like this one: Code: public class GenericClass<T> { private final Class<T> type; public GenericClass(Class<T> type) { this.type = type; } public Class<T> getMyType() { return this.type; } } that I wouldn't know how to use in b4a; anyway it doesn't seem very different from the solution proposed by @Enrique Gonzalez R and I don't know what result it would return (I fear that it would not be different). P.S. Reading your first post again (and better) I think that now you write Dim s As String = Me Log(s) directly in the Main class module, getting: class b4j.example.main I don't know what it could be useful for but that's ok. P.P.S. Why "sometimes" I am so stupid? (please, do not answer ). If I wanted the class name of a my custom class, I could simply write it directly in my getClassType property! Code: #Region PROPERTIES Public Sub getClassType As String Return 'Here my custom class name' End Sub Last edited: Jul 5, 2019 Upvote 0
I'm lost, here. I suppose you want to know the name of your custom class by getting it from an instance of your class. Simply using the suggestions, I get useless values: Code: #Region PROPERTIES Public Sub getClassType As String Dim s As String = Me Return s End Sub Using the property above I get this stuff: Class Type: [fx=anywheresoftware.b4j.objects.JFX@1a579872, mvalue=, main=null[/COLOR] I found answers on stackoverflow.com, like this one: Code: public class GenericClass<T> { private final Class<T> type; public GenericClass(Class<T> type) { this.type = type; } public Class<T> getMyType() { return this.type; } } that I wouldn't know how to use in b4a; anyway it doesn't seem very different from the solution proposed by @Enrique Gonzalez R and I don't know what result it would return (I fear that it would not be different). P.S. Reading your first post again (and better) I think that now you write Dim s As String = Me Log(s) directly in the Main class module, getting: class b4j.example.main I don't know what it could be useful for but that's ok. P.P.S. Why "sometimes" I am so stupid? (please, do not answer ). If I wanted the class name of a my custom class, I could simply write it directly in my getClassType property! Code: #Region PROPERTIES Public Sub getClassType As String Return 'Here my custom class name' End Sub