-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
1.1.2
-
sparc
-
solaris_2.5
Name: laC46010 Date: 04/15/97
Java compiler (JDK1.0.2 - JDK1.1.2) allows to access instance field
using illegal qualified expression of the following kind:
<class name>.<instance field name>
JLS (6.5.5.2 Qualified Expression Names, p.96) says:
"If an expression name is of the form Q.Id, then Q has already been
classified as a package name, a type name, or an expression name:
- If Q is a package name, then a compile-time error occurs.
- If Q is a type name that names a class type (8), then:
- If there is not exactly one accessible (6.6) member of the
class type that is a field named Id, then a compile-time error
occurs.
- Otherwise, if the single accessible member field is not a class
variable (that is, it is not declared static), then a
compile-time error occurs.
...
"
The following example is successfully compiled though
compile-time error should be reported for "SUPER.b":
--------------------------------------
class SUPER {
static int a = 1;
int b = 2;
}
public class clss02201 extends SUPER {
void test() {
System.out.println(a);
System.out.println(b);
System.out.println(SUPER.a);
System.out.println(SUPER.b); // NOT ALLOWED
System.out.println(this.a);
System.out.println(this.b);
System.out.println(super.a);
System.out.println(super.b);
}
public static void main(String args[]) {
clss02201 x = new clss02201();
x.test();
}
}
--------------------------------------
======================================================================
- duplicates
-
JDK-4071330 treats qualified access like access via simple name
- Closed