On 24-5-2005 10:50, Julian wrote:
> 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_/ /__/
/ \ /_/ / \
|