| Summary: | Bound mismatch on unused generic method parameters | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | picture.cooking |
| Component: | Core | Assignee: | Srikanth Sankaran <srikanth_sankaran> |
| Status: | VERIFIED INVALID | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | jarthana, Olivier_Thomann |
| Version: | 3.7 | ||
| Target Milestone: | 3.8 M4 | ||
| Hardware: | PC | ||
| OS: | Linux | ||
| Whiteboard: | |||
Srikanth, please investigate. See that this code does not compile with JDK7.
javac 7b147 complains:
X.java:7: error: invalid inferred types for K,O,L; inferred type does not confor
m to declared bound(s)
ServiceUtils.fails(entity);
^
inferred: Entity<Integer>
bound(s): Entity<Serializable>
where K,E,O,L are type-variables:
K extends Serializable declared in method <E,K,O,L>fails(E)
E extends OwnedEntity<K,O> declared in method <E,K,O,L>fails(E)
O extends Entity<L> declared in method <E,K,O,L>fails(E)
L extends Serializable declared in method <E,K,O,L>fails(E)
1 error
While eclipse complains:
Bound mismatch: The generic method fails(E) of type ServiceUtils is not applicable for the arguments (OwnedEntity<Integer,Entity<Integer>>). The inferred
type Entity<Integer> is not a valid substitute for the bounded parameter <O extends Entity<L>>
against the simplified test case below which can be cut & pasted into a single
file:
//---------------------------------------------------
import java.io.Serializable;
public class X {
public void fails(OwnedEntity<Integer, Entity<Integer>> entity) {
ServiceUtils.fails(entity);
}
public void works(OwnedEntity<Integer, Entity<Integer>> entity, Integer dummy) {
ServiceUtils.works(entity, dummy);
}
}
class Entity<K extends Serializable> {
K key;
}
class OwnedEntity<K extends Serializable, O extends Entity<? extends Serializable>> extends Entity<K> {
O owner;
}
class ServiceUtils {
public static <E extends OwnedEntity<K, O>, K extends Serializable, O extends Entity<L>, L extends Serializable> void fails(
E entity) {
}
public static <E extends OwnedEntity<K, O>, K extends Serializable, O extends Entity<L>, L extends Serializable> void works(
E entity, L dummy) {
}
}
// ---------------------------------------------------------------
Since eclipse behavior matches the latest javac behavior, I conclude
that this was a bug in JDK5,6 compilers which has since been fixed.
Closing this as INVALID.
Verified for 3.8M4 |
Build Identifier: 20100617-1415 The method <fails> in the following does not compile, resulting in "Bound mismatch: The generic method fails(E) of type ServiceUtils is not applicable for the arguments (OwnedEntity<Integer,Entity<Integer>>). The inferred type Entity<Integer> is not a valid substitute for the bounded parameter <O extends Entity<L>>" Whereas the method <works> does. Both compile under javac public class Service { public void fails(OwnedEntity<Integer, Entity<Integer>> entity) { ServiceUtils.fails(entity); } public void works(OwnedEntity<Integer, Entity<Integer>> entity, Integer dummy) { ServiceUtils.works(entity, dummy); } } public class Entity<K extends Serializable> { K key; } public class OwnedEntity<K extends Serializable, O extends Entity<? extends Serializable>> extends Entity<K> { O owner; } public class ServiceUtils { public static <E extends OwnedEntity<K, O>, K extends Serializable, O extends Entity<L>, L extends Serializable> void fails( E entity) { } public static <E extends OwnedEntity<K, O>, K extends Serializable, O extends Entity<L>, L extends Serializable> void works( E entity, L dummy) { } } Reproducible: Always Steps to Reproduce: 1. Attempt to compile