Skip to content

Instantly share code, notes, and snippets.

@juherr
Last active June 23, 2016 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juherr/c3f70f4b80c5f98a47aa6cb9b5bb14ef to your computer and use it in GitHub Desktop.
Save juherr/c3f70f4b80c5f98a47aa6cb9b5bb14ef to your computer and use it in GitHub Desktop.
Eclipse compiler issue
package test;
public class CompileClass2 {
private void addInstance(MyClass<?> clazz) {
addInstance(clazz.getFoo(), clazz.getBar()); // <- compiler issue here
addInstance2(clazz.getFoo(), clazz.getBar());
}
private <T> void addInstance2(MyClass<T> clazz) {
addInstance(clazz.getFoo(), clazz.getBar()); // <- no compiler issue here
addInstance2(clazz.getFoo(), clazz.getBar());
}
private <T, S extends T> void addInstance(Class<S> foo, T bar) {
}
private <T> void addInstance2(Class<? extends T> foo, T bar) {
}
static class MyClass<T> {
Class<? extends T> getFoo() {
return null;
}
T getBar() {
return null;
}
}
}

With openjdk 1.7.0_101 OR oracle 1.8.0_91 + compiler compliance level 1.7

Description Resource Path Location Type Bound mismatch: The generic method addInstance(Class, T) of type CompileClass2 is not applicable for the arguments (Class<capture#2-of ? extends capture#1-of ?>, capture#3-of ?). The inferred type capture#2-of ? extends capture#1-of ? is not a valid substitute for the bounded parameter CompileClass2.java /test-compile/src/test line 6 Java Problem

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