Reflection

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Reflection

Peter-2
Hello fellow Kawa programmers!

I'm trying to reflect on Classes, however, I'm running into some
problems:

> ("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
Reply | Threaded
Open this post in threaded view
|

Re: Reflection

Per Bothner
On 09/27/2017 07:55 AM, Peter wrote:

> I'm trying to reflect on Classes, however, I'm running into some
> problems:
>
>> ("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
[hidden email]   http://per.bothner.com/
Reply | Threaded
Open this post in threaded view
|

Re: Reflection

Jamison Hope
On Wed, September 27, 2017 11:28 am, Per Bothner wrote:

> On 09/27/2017 07:55 AM, Peter wrote:
>> I'm trying to reflect on Classes, however, I'm running into some
>> problems:
>>
>>> ("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)

Using "*:" notation works, too:

(*:getCanonicalName ("foo":getClass))

--
Jamison Hope
[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Reflection

Peter-2
>> This is explained in
>> https://www.gnu.org/software/kawa/Colon-notation.html

Ah, sorry for missing this ;-/

> Using "*:" notation works, too:
> (*:getCanonicalName ("foo":getClass))

That'll do perfectly ;) Thanks to both of you for the help!

Greetings, Peter