Discussion:
Reflection
Peter
2017-09-27 14:55:54 UTC
Permalink
Hello fellow Kawa programmers!

I'm trying to reflect on Classes, however, I'm running into some
("foo":getClass)
class java.lang.String
(("foo":getClass):getCanonicalName)
; Evaluation aborted on java.lang.RuntimeException: no applicable method named `getCanonicalName' in java.lang.String.
(java.lang.String:getCanonicalName)
; Evaluation aborted on java.lang.RuntimeException: no such field getCanonicalName in java.lang.String.
(<java.lang.String>:getCanonicalName)
; Evaluation aborted on java.lang.RuntimeException: no such field getCanonicalName in java.lang.String.


How do I correctly use reflection (for finding methods and fields etc.)?

Thanks for any help!

Peter
Per Bothner
2017-09-27 15:28:49 UTC
Permalink
Post by Peter
I'm trying to reflect on Classes, however, I'm running into some
("foo":getClass)
class java.lang.String
(("foo":getClass):getCanonicalName)
; Evaluation aborted on java.lang.RuntimeException: no applicable method named `getCanonicalName' in java.lang.String.
(java.lang.String:getCanonicalName)
; Evaluation aborted on java.lang.RuntimeException: no such field getCanonicalName in java.lang.String.
(<java.lang.String>:getCanonicalName)
; Evaluation aborted on java.lang.RuntimeException: no such field getCanonicalName in java.lang.String.
This is explained in
https://www.gnu.org/software/kawa/Colon-notation.html

However, that doesn't say what to do instead. (I'm adding a note for that.)

Basically, if the "receiver" (this) argument is a Class then you can't use
colon notation, but you can use the invoke procedure:

(invoke ("foo":getClass) 'getCanonicalName)
--
--Per Bothner
***@bothner.com http://per.bothner.com/
Jamison Hope
2017-09-27 15:35:11 UTC
Permalink
Post by Per Bothner
Post by Peter
I'm trying to reflect on Classes, however, I'm running into some
("foo":getClass)
class java.lang.String
(("foo":getClass):getCanonicalName)
; Evaluation aborted on java.lang.RuntimeException: no applicable method
named `getCanonicalName' in java.lang.String.
(java.lang.String:getCanonicalName)
; Evaluation aborted on java.lang.RuntimeException: no such field
getCanonicalName in java.lang.String.
(<java.lang.String>:getCanonicalName)
; Evaluation aborted on java.lang.RuntimeException: no such field
getCanonicalName in java.lang.String.
This is explained in
https://www.gnu.org/software/kawa/Colon-notation.html
However, that doesn't say what to do instead. (I'm adding a note for that.)
Basically, if the "receiver" (this) argument is a Class then you can't use
(invoke ("foo":getClass) 'getCanonicalName)
Using "*:" notation works, too:

(*:getCanonicalName ("foo":getClass))
--
Jamison Hope
***@theptrgroup.com
Peter
2017-09-27 15:56:26 UTC
Permalink
Post by Jamison Hope
Post by Per Bothner
This is explained in
https://www.gnu.org/software/kawa/Colon-notation.html
Ah, sorry for missing this ;-/
Post by Jamison Hope
(*:getCanonicalName ("foo":getClass))
That'll do perfectly ;) Thanks to both of you for the help!

Greetings, Peter

Loading...