public static void main(String[] args) {
List extends Object> mylist = new ArrayList
Let's say you have an interface and two classes:
interface IResult {}
class AResult implements IResult {}
class BResult implements IResult {}
Then you have classes that return a list as a result:
interface ITest {
List getResult();
}
class ATest implements ITest {
// look, overridden!
List getResult();
}
class BTest implements ITest {
// overridden again!
List getResult();
}
It's a good solution, when you need "covariant returns", but you return collections instead of your own objects. The big plus is that you don't have to cast objects when using ATest and BTest independently from the ITest interface. However, when using ITest interface, you cannot add anything to the list that was returned - as you cannot determine, what object types the list really contains! If it would be allowed, you would be able to add BResult to List
So you have to remember this: List extends X> defines a list that could be easily overridden, but which is read-only.