-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
6u10
-
x86
-
linux
FULL PRODUCT VERSION :
java -version
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01, mixed mode)
javac -version
javac 1.6.0_20
ADDITIONAL OS VERSION INFORMATION :
Linux cave 2.6.31-22-generic #60-Ubuntu SMP Thu May 27 02:41:03 UTC 2010 x86_64 GNU/Linux
Darwin K.local 10.4.0 Darwin Kernel Version 10.4.0: Fri Apr 23 18:28:53 PDT 2010; root:xnu-1504.7.4~1/RELEASE_I386 i386
A DESCRIPTION OF THE PROBLEM :
When multiple inheritance exist in an interface hierarchy, compiler can't handle covariant return types correctly.
See the test case below. Compiler complains about getV() in I3, saying I1 and I2 (superinterfaces of I3) define incompatible return types for method getV(). However, I3's return type V3 is a subinterface of V1 and V2 and hence the code is valid.
Eclipse's built in compiler successfully compiles this code.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The code should compile without errors.
ACTUAL -
The code doesn't compile.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
src/java/Covariant.java:29: types Covariant.I2 and Covariant.I1 are incompatible; both define getV(), but with unrelated return types
interface I3 extends I1, I2 {
^
1 error
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class Covariant {
// return types
interface V {}
interface V1 extends V {}
interface V2 extends V {}
interface V3 extends V1, V2 {}
interface I {
V getV();
}
interface I1 extends I {
V1 getV();
}
interface I2 extends I {
V2 getV();
}
interface I3 extends I1, I2 {
V3 getV();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Omit the declaration in interfaces and cast return type to proper type.
java -version
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01, mixed mode)
javac -version
javac 1.6.0_20
ADDITIONAL OS VERSION INFORMATION :
Linux cave 2.6.31-22-generic #60-Ubuntu SMP Thu May 27 02:41:03 UTC 2010 x86_64 GNU/Linux
Darwin K.local 10.4.0 Darwin Kernel Version 10.4.0: Fri Apr 23 18:28:53 PDT 2010; root:xnu-1504.7.4~1/RELEASE_I386 i386
A DESCRIPTION OF THE PROBLEM :
When multiple inheritance exist in an interface hierarchy, compiler can't handle covariant return types correctly.
See the test case below. Compiler complains about getV() in I3, saying I1 and I2 (superinterfaces of I3) define incompatible return types for method getV(). However, I3's return type V3 is a subinterface of V1 and V2 and hence the code is valid.
Eclipse's built in compiler successfully compiles this code.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The code should compile without errors.
ACTUAL -
The code doesn't compile.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
src/java/Covariant.java:29: types Covariant.I2 and Covariant.I1 are incompatible; both define getV(), but with unrelated return types
interface I3 extends I1, I2 {
^
1 error
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class Covariant {
// return types
interface V {}
interface V1 extends V {}
interface V2 extends V {}
interface V3 extends V1, V2 {}
interface I {
V getV();
}
interface I1 extends I {
V1 getV();
}
interface I2 extends I {
V2 getV();
}
interface I3 extends I1, I2 {
V3 getV();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Omit the declaration in interfaces and cast return type to proper type.