public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
* Reflection
@ 2017-09-27 14:56 Peter
  2017-09-27 15:29 ` Reflection Per Bothner
  0 siblings, 1 reply; 4+ messages in thread
From: Peter @ 2017-09-27 14:56 UTC (permalink / raw)
  To: kawa mailing list

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Reflection
  2017-09-27 14:56 Reflection Peter
@ 2017-09-27 15:29 ` Per Bothner
  2017-09-27 15:35   ` Reflection Jamison Hope
  0 siblings, 1 reply; 4+ messages in thread
From: Per Bothner @ 2017-09-27 15:29 UTC (permalink / raw)
  To: Peter, kawa mailing list

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
per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Reflection
  2017-09-27 15:29 ` Reflection Per Bothner
@ 2017-09-27 15:35   ` Jamison Hope
  2017-09-27 15:56     ` Reflection Peter
  0 siblings, 1 reply; 4+ messages in thread
From: Jamison Hope @ 2017-09-27 15:35 UTC (permalink / raw)
  To: kawa mailing list

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
jrh@theptrgroup.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Reflection
  2017-09-27 15:35   ` Reflection Jamison Hope
@ 2017-09-27 15:56     ` Peter
  0 siblings, 0 replies; 4+ messages in thread
From: Peter @ 2017-09-27 15:56 UTC (permalink / raw)
  To: jrh, kawa mailing list

>> 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-09-27 15:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-27 14:56 Reflection Peter
2017-09-27 15:29 ` Reflection Per Bothner
2017-09-27 15:35   ` Reflection Jamison Hope
2017-09-27 15:56     ` Reflection Peter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).