Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
///System.TypeException: Invalid conversion from runtime type LIST to LIST
List<Object> objects = new List<Object>{'a','a','b','c','c','c','d','e','e'};
List<String> strings = (List<String>)objects;
System.debug(strings.size());
//WORKS
List<String> stringList = new List<String>{'a','a','b','c','c','c','d','e','e'};
List<Object> objects = (List<Object>)stringList;
System.debug(objects.size());
//WORKS
List<String> stringList = new List<String>{'a','a','b','c','c','c','d','e','e'};
System.assertEquals(9, stringList.size());
Set<String> stringSet = new Set<String>(stringList);
System.debug('String Set Size = ' + stringSet.size());
//Incompatible argument type LIST for All method on SET
List<String> stringList = new List<String>{'a','a','b','c','c','c','d','e','e'};
System.assertEquals(9, stringList.size());
Set<Object> objectSet = new Set<Object>(stringList);
System.debug('Object Set Size = ' + objectSet.size());
//WORKS
List<String> stringList = new List<String>{'a','a','b','c','c','c','d','e','e'};
System.assertEquals(9, stringList.size());
Set<Object> objectSet = new Set<Object>((List<Object>)stringList);
System.debug('Object Set Size = ' + objectSet.size());
//WORKS
List<Object> objects = new List<Object>{'a','a','b','c','c','c','d','e','e'};
List<String> strings = new List<String>();
for(Object o : objects){
strings.add((String)o);
}
System.debug(strings.size());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment