How to get the type of an object?

779 views
Skip to first unread message

Freewind

unread,
Jun 18, 2012, 1:02:41 PM6/18/12
to xtend...@googlegroups.com
I have an instance of some class, how to get its type?

In java:

    obj.getClass()

How to do it in xtend?

Sebastian Zarnekow

unread,
Jun 18, 2012, 1:05:45 PM6/18/12
to xtend...@googlegroups.com
Did you try obj.getClass() ? ;-)
signature.asc

Sven Efftinge

unread,
Jun 18, 2012, 1:07:17 PM6/18/12
to xtend...@googlegroups.com
obj.getClass()

:-)

also

obj.getClass

and

obj.^class

(the '^' is required to escape identifiers conflicting with keywords)

The reason why you didn't find it in the first place, is that content assist doesn't propose it.
It's know bug and will be fixed soon.

Sven

Freewind

unread,
Jun 18, 2012, 1:07:39 PM6/18/12
to xtend...@googlegroups.com
You are right :-p

Zsombor

unread,
Jun 18, 2012, 1:08:04 PM6/18/12
to xtend...@googlegroups.com

It's a pretty common question, as it doesn't have an obvious solution. Is there any fundemantal issue, supporting the java like myObj.getClass and String.class expressions?

Regards
Zsombor

Sebastian Zarnekow

unread,
Jun 18, 2012, 1:28:51 PM6/18/12
to xtend...@googlegroups.com
obj.getClass does the job as expected. String.class was more difficult to get right from a technical perspective thus we decided to go for typeof(String) instead. I actually prefer that syntax over String.class.

Regards,
Sebastian
signature.asc
Reply all
Reply to author
Forward
0 new messages