Skip to content

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

Description

@dapengzhang0
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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions