Java Covariants

后端 未结 7 851
臣服心动
臣服心动 2021-01-01 22:26
public class CovariantTest {
    public A getObj() {
        return new A();
    }

    public static void main(String[] args) {
        CovariantTest c = new SubCov         


        
7条回答
  •  一个人的身影
    2021-01-01 22:56

    Replace your A and B above with:

    class A {
        public int getX() { return 5; }
    }
    
    class B extends A {
        public int getX() { return 6; }
     }
    

    That will probably answer your question about what is wrong ;-)

提交回复
热议问题