how to get info of array type in runtime?

Discussion in 'Java' started by szczepiq, Jan 10, 2009.

  1. szczepiq

    szczepiq Guest

    How to get info of array type in runtime?

    String[] arr = new String[0];

    assert arr.getType().isArray();

    arr.getType().dearArrayTellMeWhatTypesYouAccept();
    szczepiq, Jan 10, 2009
    #1
    1. Advertising

  2. szczepiq

    Roedy Green Guest

    On Sat, 10 Jan 2009 10:14:52 -0800 (PST), szczepiq
    <> wrote, quoted or indirectly quoted someone who
    said :

    >
    >String[] arr = new String[0];
    >
    >assert arr.getType().isArray();
    >
    >arr.getType().dearArrayTellMeWhatTypesYouAccept();


    Have a look at instanceof, isInstanceOf, and getClass

    http://mindprod.com/jgloss/instanceOf


    how does this compile/evaluate?

    String[] x = new String[10];

    boolean is = x instanceof Object[];

    -------------

    Object[] x = new String[10];

    boolean is = x instanceof String[];



    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    PM Steven Harper is fixated on the costs of implementing Kyoto, estimated as high as 1% of GDP.
    However, he refuses to consider the costs of not implementing Kyoto which the
    famous economist Nicholas Stern estimated at 5 to 20% of GDP
    Roedy Green, Jan 11, 2009
    #2
    1. Advertising

  3. szczepiq

    Daniel Pitts Guest

    Roedy Green wrote:
    > On Sat, 10 Jan 2009 10:14:52 -0800 (PST), szczepiq
    > <> wrote, quoted or indirectly quoted someone who
    > said :
    >
    >> String[] arr = new String[0];
    >>
    >> assert arr.getType().isArray();
    >>
    >> arr.getType().dearArrayTellMeWhatTypesYouAccept();

    >
    > Have a look at instanceof, isInstanceOf, and getClass
    >
    > http://mindprod.com/jgloss/instanceOf
    >
    >
    > how does this compile/evaluate?
    >
    > String[] x = new String[10];
    >
    > boolean is = x instanceof Object[];
    >
    > -------------
    >
    > Object[] x = new String[10];
    >
    > boolean is = x instanceof String[];
    >
    >
    >


    or see getClass().getComponentType()

    --
    Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
    Daniel Pitts, Jan 12, 2009
    #3
    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. Vasanth
    Replies:
    0
    Views:
    529
    Vasanth
    Jun 28, 2004
  2. Andrea Williams

    Clear the Render info & change to different info

    Andrea Williams, Oct 27, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,398
    Ken Dopierala Jr.
    Oct 27, 2004
  3. ilya

    get CPU info, RAM info

    ilya, Apr 8, 2010, in forum: Java
    Replies:
    43
    Views:
    5,929
    Mike Schilling
    Apr 19, 2010
  4. Goran Pusic
    Replies:
    4
    Views:
    594
    Andrey Tarasevich
    Sep 8, 2010
  5. Dao Shi
    Replies:
    3
    Views:
    116
    Eric Hodel
    Dec 4, 2006
Loading...

Share This Page