List<?> which is equivalent to List<? extends Object> allows the functionality you need:
public class otherclass : extends Object {
public List<Object> getDataList(){} // It returns a List<Object>
}
// In your code you can cast it like this:
List<? extends Object> o = getDataList();
if( o != null ){
List<otherclass> myList = (List<otherclass>) o;
// From now on you can use myList as a List<otherclass> reference to the List object o;
}else{
// Error handling...
}
public class otherclass : extends Object {
public List<Object> getDataList(){} // It returns a List<Object>
}
// In your code you can cast it like this:
List<? extends Object> o = getDataList();
if( o != null ){
List<otherclass> myList = (List<otherclass>) o;
// From now on you can use myList as a List<otherclass> reference to the List object o;
}else{
// Error handling...
}
public List<Object> getDataList(){} // It returns a List<Object>
}
public class TestClass extends otherclass{
// I can't cast its list here to List<otherclass>. Compile fires an error at:
List<otherclass> o = (List<otherclass>)getDataList();
}