9

Why can I compile this code without errors:

public class Base<T> {
    Base(List<String> list){}
}

class Child extends Base{
    Child(){
        super(new ArrayList<Integer>());
    }
}

But at the same time I can't compile this one (pay attention to Base<T>):

public class Base {
    Base(List<String> list){}
}

class Child extends Base{
    Child(){
        super(new ArrayList<Integer>());
    }
}

Obviously, there is "incompatible types" in the second example, but why is there no errors in the first one? It is unsafe and can lead to runtime exceptions, can't it?

peremeykin
  • 519
  • 5
  • 11

0 Answers0