I meet absolutely strange behavior of the Java compiler.
I cannot distinguish between a supertype and a subtype when a cyclic general type is a relation .
JUnit test to reproduce the problem:
public class _SupertypeGenericTest {
interface ISpace<S extends ISpace<S, A>, A extends IAtom<S, A>> {
}
interface IAtom<S extends ISpace<S, A>, A extends IAtom<S, A>> {
}
static class Space
implements ISpace<Space, Atom> {
}
static class Atom
implements IAtom<Space, Atom> {
}
public void test() {
ISpace<?, ?> spaceSupertype = new Space();
IAtom<?, ?> atomSupertype = new Atom();
Space space = (Space) spaceSupertype;
Atom atom = (Atom) atomSupertype;
}
}
Compiler Error Output:
_SupertypeGenericTest.java:33: inconvertible types
found : pinetag.data._SupertypeGenericTest.ISpace<capture#341 of ?,capture#820 of ?>
required: pinetag.data._SupertypeGenericTest.Space
Space space = (Space) spaceSupertype;
^
_SupertypeGenericTest.java:34: inconvertible types
found : pinetag.data._SupertypeGenericTest.IAtom<capture#94 of ?,capture#48 of ?>
required: pinetag.data._SupertypeGenericTest.Atom
Atom atom = (Atom) atomSupertype;
^
2 errors
Note. I use the latest version of Netbeans, bundled Ant, the latest version of Java 6.
I tried to use Ant from the command line (Netbeans generates a build.xml file), but this leads to the same errors.
What's wrong?
Is there an elegant way to solve the problem?
The strange thing: Netbeans does not put errors (even warnings) in the given code.
EDIT:
, !
Eclipse 3.4.1 , ,
!!!
? , Ant
build.xml, Netbeans ', .
- ?
2:
JDK7 JDK7, netbeans
/!
( 1.7.0-ea-b55)
3:
, , javac.