The easiest way is to use inheritance. The best way is to use object composition.
How will you decide which object you want to cast it into? Why does your "List object" not contain a parameter. Techincally, you can put anything inside a list, what makes this list unique? How do you determine what makes each user unique?
Consider this code:
DeskObjectIterator doi = new DeskObjectIterator(deskObjectArrayOrList);
while(doi.hasNext())
{
DeskObject deskObject = doi.next();
if(deskObject instanceof Pen)
Pen pen = (Pen)deskObject;
else if(deskObject instanceof Computer)
Computer computer = (Computer)deskObject;
// else if ...
}
or ...
DeskObjectIterator doi = new DeskObjectIterator(deskObjectArrayOrList);
while(doi.hasNext())
{
DeskObject deskObject = doi.next();
if(deskObject.typeString.equals("Pen"))
Pen pen = (Pen)deskObject;
else if(deskObject.typeString.equals(Computer))
Computer computer = (Computer)deskObject;
// else if ...
}