Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2005

Tip: Looking for answers? Try searching our database.

Reflection: Get a Class-Iinstance of a Wrapper Class - why .TYPE?

Thread view: 
Julian - 24 May 2005 09:47 GMT
Good morning,

can anyone explaine me the reason why every Wrapper-Class (like
Integer) has this special constant .TYPE? These Wrapper-Classes provide
the normal getClass()-Method as well and I therefore don't understand
the sense of the .TYPE constant.
Thank you very much in advance!

Greetings from sunny Kiel

Julian Wissel
Roland - 24 May 2005 10:16 GMT
> Good morning,
>
[quoted text clipped - 7 lines]
>
> Julian Wissel

It represents the class of the *primitive*, i.e. not the class of the
wrapper class.

Wrapper              Primitive
Integer.class        int.class   (== Integer.TYPE)
Character.class      char.class  (== Character.TYPE)
Float.class          float.class (== Float.TYPE)
etc.

Used when obtaining a Method that has a primitive parameter. E.g. to get
the static method toString(int) of class Integer:

Integer.class.getDeclaredMethod("toString", new Object[]{Integer.TYPE});

or

Integer.class.getDeclaredMethod("toString", new Object[]{int.class});
Signature

Regards,

Roland de Ruiter
  ___      ___
 /__/ w_/ /__/
/  \ /_/ /  \

Dale King - 26 May 2005 04:46 GMT
>> Good morning,
>>
[quoted text clipped - 25 lines]
>
> Integer.class.getDeclaredMethod("toString", new Object[]{int.class});

And if you are wondering why we have two ways of doing the same thing,
the class literal (i.e. int.class) did not exist in the original version
of Java and were added later.

Signature

 Dale King



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.