• 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

Confusion about Primitive Types

 
Greenhorn
Posts: 16
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Hi,
I am viewing the source code of java.lang.Class class.
I could not understand the statement
" The primitive Java types (boolean, byte, char, short, int, long, float, and double), and the keyword void are also represented as Class objects."
Can anyone elaborate the exact meaning of above line.

Thanks in advance
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jaikant Singh wrote:
I am viewing the source code of java.lang.Class class.
I could not understand the statement
" The primitive Java types (boolean, byte, char, short, int, long, float, and double), and the keyword void are also represented as Class objects."
Can anyone elaborate the exact meaning of above line.




Well, you kinda took that sentence out of context somewhat -- but basically...

Instances of the Class class can be use to represent *all* data types. The complete paragraph list everything. And the last sentence (this one), says that it there are also Class instances for the primitives types too. Kinda makes sense if you think about it; otherwise, how would you use the reflection libraries for components that use primitive data types?

Henry
 
Jaikant Singh
Greenhorn
Posts: 16
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Henry,

But I know there are Wrapper Classes for converting into Objects then why I need to use Class instances for primitive types apart from using it in reflection library for components.
Do you have an example of that?

JAIKANT

 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jaikant Singh wrote:
But I know there are Wrapper Classes for converting into Objects then why I need to use Class instances for primitive types apart from using it in reflection library for components.
Do you have an example of that?



Do you actually need any other reason? Reflection would be arguably broken without this capability.


Also, this isn't about converting primitive types into objects. The Class class is used to represent types. This is about the ability of the Class class to represent primitive types.

Henry
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a simpler way primitive types are the data types which are provided by java to declare variables of respective types. void is a key word of java which is used in implementing a method which does not intend to return any value.



eg:-

reply
    Bookmark Topic Watch Topic
  • New Topic