how to get info of array type in runtime?

S

szczepiq

How to get info of array type in runtime?

String[] arr = new String[0];

assert arr.getType().isArray();

arr.getType().dearArrayTellMeWhatTypesYouAccept();
 
R

Roedy Green

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
 
D

Daniel Pitts

Roedy 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()
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top