In the above code i dont have any Issues.I can get list of userId and userName from the List.

How i can cast the Object dynamically.

UserDto users = (UserDto)hritr.next();
in this code i dont want to put UserDto,this should by dynamic Class.
Because the list may contain,List of users,List of Customers etc.

How this can be achieved in java..Can i use reflection?
Please help me to overcome this issue.

February 23rd, 2012, 03:46 PM

kenster421

Re: Dymaic Casting of List

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?