0

Below is a code example, which causes a compile error.

    class A<T extends Number> {
        T a;

        T getA() {
            return a;
        }
    }

    class B<U> extends A<Integer> {
        public void test() {
            Integer i = getA();//fine
            B b = new B();
            Integer i1 = b.getA(); //Ooop !! has an error!!!
            Number i2=b.getA(); //fine
        }
    }

If I remove the <U> generic symbol or use B<?> b = new B();, then it compiles well. Is the code above violating any java specification.

choxsword
  • 3,187
  • 18
  • 44

0 Answers0