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

Discussion in 'Java' started by Julian, May 24, 2005.

  1. Julian

    Julian Guest

    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
    Julian, May 24, 2005
    #1
    1. Advertising

  2. Julian

    Roland Guest

    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_/ /__/
    / \ /_/ / \
    Roland, May 24, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Feldman

    Type Reflection and Code Directory

    Andrew Feldman, Dec 17, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,086
    Andrew Feldman
    Dec 20, 2004
  2. Paul Joel
    Replies:
    5
    Views:
    369
    Chris Smith
    Sep 24, 2003
  3. M. Faust
    Replies:
    0
    Views:
    387
    M. Faust
    Oct 18, 2004
  4. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    855
    Mark Rae
    Dec 21, 2006
  5. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,756
    Smokey Grindel
    Dec 2, 2006
Loading...

Share This Page