Relates :
|
|
Relates :
|
|
Relates :
|
Two recent bug reports (4096303 and 4094180) have once again raised issues concerning the use of '$' characters in Java identifiers. The JLS states that "The '$' character should be used only in mechanically generated Java code or, rarely, to access pre-existing names on legacy systems." Thus, although discouraged in ordinary usage, the compiler cannot rule out such names, and the reservation of certain names by the inner class mechanism is indeed an incompatible change to the Java language (as it existed prior to 1.1) that must be precisely defined. The following program illustrates three of the ways in which a name appearing in Java source can conflict with a name generated implicitly by the compiler according to the inner classes specification: class C { class N { int this$0; //BAD } } class C$N { } //BAD class Baz { void quux() { class Quem {} } } class Baz$1$Quem {} //BAD It is not sufficient merely to advise users against using '$' in identifiers, as we must offer guidance to those who are writing automatic program generators for whom we have ostensibly reserved such names. william.maddox@Eng 1997-12-09 Name: skT45625 Date: 05/10/2000 java version "1.3.0" Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C) Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode) Starting with JDK 1.3, javac breaks on "this$0" references. Try compiling the following example: public class TestInner { public class Inner { public void test() { System.out.println("My outer class: "+this$0); } } public void test() { Inner inner = new Inner(); inner.test(); } static public void main(String[] args) { TestInner inner = new TestInner(); inner.test(); } } C:\Current\Server>javac *.java TestInner.java:6: cannot resolve symbol symbol : variable this$0 location: class TestInner.Inner System.out.println("My outer class: "+this$0); (Review ID: 104660) ======================================================================
|