display object class type

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

display object class type

Damien Mattei
Hi,

for debugging purpose i wanted to display the type of an object in kawa,

i compile this:

(display (type1:getClass:getName) )

ok for compiling but when running i got a Null pointer:

#!null

???

strange ,is there a way to make it work?

my object is not Null it display as B5 , a string (java.langString or FString or gnu.text.char .... i do not know but not Null

Damien
--
[hidden email], [hidden email], UNS / OCA / CNRS
Reply | Threaded
Open this post in threaded view
|

Re: display object class type

Per Bothner


On 01/13/2017 06:59 AM, Damien MATTEI wrote:

> (display (type1:getClass:getName) )
>
> ok for compiling but when running i got a Null pointer:
>
> #!null
>
> ???
>
> strange ,is there a way to make it work?
>
> my object is not Null it display as B5 , a string (java.langString or FString or gnu.text.char .... i do not know but not Null

It's confusing, but it's because colon notation tries to do so much ...

There are two problems:

(1) You can write either
   (type1:getClass)    ; call getClass method of type1
or:
   type1:class        ; get class property of type1

Either works, because an X property can resolve either to an X field
or a getX method.

However, if you leave out the (inner) parens:
   type1:getClass
you get a procedure that *if* you apply it calls the getClass method.

(2) There is an unfortunate ambiguity between:
   (object:method-name arg ...) ; instance method invocation
   (Class:method-name arg ...)  ; static method invocation

type1:class (or (type1:getName)) returns a class, so for
   (type1:class:getName)
looks for the static method getName in the class of type1.

Summary: you should write:

   (invoke type1:class 'getName)

Seehttps://www.gnu.org/software/kawa/Method-operations.html
--
        --Per Bothner
[hidden email]   http://per.bothner.com/