My method returns a list of Object. I wanted to add that to a list of specific SObject.
List<Account> accList = new List<Account>();
List<Object> objList = new List<Object>(returnRecordList(List<Account>.class, recordList));
accList.addAll((List<Account>)objList);
static List<Object> returnRecordList (Type resListType, List<SObject> records) {
List<Object> prefEnabled = (List<Object>)resListType.newInstance();
system.debug(prefEnabled);
return prefEnabled;
}
I get the error as Invalid conversion from runtime type List<ANY> to List<Account>