function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
code developercode developer 

How to cast aList<Object>?

Hi

 

 

I have a List<Object>. I need to cast this to List<A> say :

 

(List<A>) List<Object>.

 

 

but  I am getting System.TypeException: Invalid conversion from runtime type LIST<ANY> to LIST<A>.

 

 

pls help me out

 

 

Jeff MayJeff May

How about this:

 

List<Object> lo = new List<Object>();
List<Contact> lc = (List<Contact>)lo;

 

code developercode developer

It is not working.Any other suggestions please?

Jeff MayJeff May
You could always go the long route and iterate over the List and cast each member List lo = new List(); List lc = new List(); for (Object o : lo) { lc.add((Contact)o); }