• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Regarding the .class syntax

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic