Getting class Type information for Elements on a collection
Posted
by DutrowLLC
on Stack Overflow
See other posts from Stack Overflow
or by DutrowLLC
Published on 2010-05-28T23:18:32Z
Indexed on
2010/05/28
23:22 UTC
Read the original article
Hit count: 210
I would like to get gain access to the type of Object held in a Collection. Below is a simplified example of when and why I might want to do this. Is this even possible?
List<Address> addressList = new LinkedList<Address>();
Main.addElement(addressList);
Class Main{
public void addElement(Object inArgument){
List<Object> argument = (List<Object>)inArgument;
argument.add( /* WOULD LIKE TO CREATE A NEW OBJECT OF THE APPROPRIATE TYPE
HERE, IN THIS CASE, IT WOULD BE OF TYPE: "Address" */ );
}
}
© Stack Overflow or respective owner