It is about inheritance.
Now I have two classes,
Super Class
public class TestSuper {}
Sub Class
public class TestSub extends TestSuper{ private TestSub testSub; private List<TestSub> testSubList; public TestSuper getTestStub(){ return testSub; } public List<TestSuper> getTestStubList() { //compile error here return testSubList; } }
I can NOT return testSubList
, the error is Type mismatch: cannot convert from List<TestSub> to List<TestSuper>
. But why can I return testSub
?