I'm taking a look at the JLS at "http://docs.oracle.com/javase/specs/jls/se5.0/html/classes.html#8.1.3" in the section labeled "8.3 Field Declarations" eight paragraphs down where it says, "It is possible for a class to inherit more than one field with the same name (8.3.3.3). Such a situation does not in itself cause a compile-time error. However, any attempt within the body of the class to refer to any such field by its simple name will result in a compile-time error, because such a reference is ambiguous."
To illustrate this I created four
Java files, namely "Abc.java":
"Def.java":
"Ghi.java":
and "Driver.java":
Note that class {Ghi} inherits both the {common} field from {Abc} and the {common} field from {Def}, so this seems to fit the "more than one field with the same name" description in the JLS. Sure enough, when I type in "javac Driver.java", all the files compile successfully, and when I type in "java Driver 314 159 265 358 979" I get results:
rst: 159
uvw: 358
xyz: 979
But the JLS seems to be saying that if I modify "Ghi.java" like so:
and then try to compile "Ghi.java" I should get a compilation error, since my reference to {common} in method {anal()} is ambiguous; it could be either the {common} field from {Abc} or the {common} field from {Def}. However when I type in "javac Ghi.java" it compiles just fine, and when I type in that same
string, "java Driver 314 159 265 358 979" I get results:
rst: 159
uvw: 358
xyz: 979
common: 265
Is this a bug with my compiler? If this isn't a case of what this paragraph in section 8.3 says
shouldn't compile, then what is?
Kevin Simonson