Hello!
I want to create an abstract collection class (called Space) and an abstract element class (called Atom). Instances of both have to know each other (exactly typed). That's the problem.
abstract class Space<A extends Atom>{
// ...
}
abstract class Atom<S extends Space>{
// ...
}
Not good:
"A extends Atom" means any Atom, but not a strongly typed one
"S extends Space" means any Space, but not a strongly typed one
I can't reach complete type-safety with the following attempts either:
abstract class Space<A extends Atom<? extends Space>>
abstract class Atom<S extends Space<? extends Atom>>
abstract class Space<S, A extends Atom<S extends Space<A>>>
abstract class Atom<A, S extends Space<A extends Atom<S>>>
and so on ...
Remember, these two classes are abstract, and I want that any possible two subclasses are typed according to each other. That means, the classes SomeSpace and SomeAtom in the following example must have a strong "type knowledge" of each other:
class SomeSpace extends Space<SomeAtom>
class SomeAtom extends Atom<SomeSpace>