I am returning a List of objects with just the type Object. However I know that these objects are of class CustomClass in this case.
When I attempt to cast the original list to the CustomClass I get an error.
This is how I'm working around it currently and it works but I don't like the fact I have a for loop just to do this.
List<Object> objects = getObjects(); List<CustomClass> customObjects = new ArrayList<>(); for ( Object object : objects ) { if ( object instanceof CustomClass ) customObjects.add( (CustomClass) object ); } Any ideas?
getObjects()method to returnList<CustomClass>?List<Custom> c = filter(objects, Custom.class);)