• Post Reply Bookmark Topic Watch Topic
  • New Topic

Regarding the .class syntax  RSS feed

 
ven jovovich
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I found the below mentioned statement here: http://docs.oracle.com/javase/tutorial/reflect/class/classNew.html
Class c = boolean.class; // correct

Somehow it doesn't compile on my machine (JDK 1.6).
My code:

Error:

Please help.

Regards,
Ven.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right: the ".class" syntax works with class names, not with objects. That's what the error message "cannot find symbol : class b" is trying to tell you.

If you need a Class object for some random object, call its getClass() method. That doesn't work for primitives, though (like a boolean), but it does work for objects (like a Boolean).
 
ven jovovich
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ulf,

A thousand apologies.... somehow I managed to interpret "Class c = boolean.class;" as "boolean b; Class c = b.class;".

Regards,
Ven.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!