java-oo icon indicating copy to clipboard operation
java-oo copied to clipboard

java-oo does not work for class whose superclass is parametrized by generic type

Open dapengzhang0 opened this issue 7 years ago • 0 comments

public abstract class Abstract {
    static class Base<T> {
        public T add(T a) {
	    return a;
	}
    }
    
    static class Ext extends Base<Integer> {
    }

    public static boolean test() {
        Integer a = new Ext().add(new Integer(1));  // this can compile
        Integer b = new Ext() + new Integer(1);   // this can not compile!
        return true;
    }
}
Running JCPOOTest
Note: Injecting OO to javac8
../tests/Abstract.java:14: error: incompatible types: T cannot be converted to Integer
                Integer b = new Ext() + new Integer(1);  // this can not compile!
                                      ^
  where T is a type-variable:
    T extends Object declared in class Base
1 error

dapengzhang0 avatar Aug 01 '17 01:08 dapengzhang0