|
Description
|
...The following program fails to compile (1.0-1.3 prototypes) with an error
about "cyclic inheritance involving F":
---
class G<N extends Node<N>> {
static class Node<N extends Node<N>> {
}
}
class F extends G<MyNode> {
static class MyNode extends G.Node<MyNode> {
}
}
---
Making F.MyNode a separate class MyNode instead of an inner class fixes
the problem; see the attached sunbug.tgz for full details. I can't read
the JLS definition of cyclic inheritance (JLS 8.1.3/9.1.2/14.3, although
8.1.3 is the only applicable section) as prohibiting this code in any
way, but then again 8.1.3 doesn't really state whether F.MyNode is meant
to "depend on" F or not. The same program stripped of type parameters
(again, see sunbug.tgz) compiles without errors, which leads me to think
this is an error in how type parameters play into the cyclic inheritance
definition.
This is a relevant problem because it will arise in any definition of a
Graph interface using an inner class Graph.Node to represent nodes. An
actual implementation of the interface will want to have code like the
above, leading to a confusing-at-best likely-erroneous situation.
|