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

J

Julian

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
 
R

Roland

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
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});
--
Regards,

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top