Finding the specific type held in an ArrayList<Object> (ie. Object = String, etc.)
Posted
by
Christopher Griffith
on Stack Overflow
See other posts from Stack Overflow
or by Christopher Griffith
Published on 2011-11-16T01:46:43Z
Indexed on
2011/11/16
1:50 UTC
Read the original article
Hit count: 144
Say I have an ArrayList that I have cast to an ArrayList of objects. I know that all the objects that were in the ArrayList I cast were of the same type, but not what the type was.
Now, if the ArrayList is not empty, I could take one of the objects in it and use the instanceof operator to learn what the actual type is. But what of the case where the ArrayList is empty? How do I determine what type Object actually is then? Is it possible?
© Stack Overflow or respective owner