Duplicate :
|
|
Relates :
|
|
Relates :
|
Name: poR10007 Date: 04/28/2001 Javac (jdk1.4.0beta-b62, jdk1.3.1-b23) allows access to a local class by using a synthetic name that compiler constructs to represent a local class. Through this synthetic name the class is accessible even outside of its scope. That contradicts the following assertions of JLS-2, 14.3 "Local class declarations": "The scope of a local class declared in a block is the rest of the immediately enclosing block, including its own class declaration." "A local class does not have a canonical name, nor does it have a fully qualified name." The following test demonstrates the behavior: --stmt16503_a.java-------------------------------------------- public class stmt16503_a { public static void test() { class Local {}; } } -------------------------------------------------------------- --stmt16503.java---------------------------------------------- public class stmt16503 { public static void main(String argv[]) { Object a = new stmt16503_a$1$Local(); } } -------------------------------------------------------------- The class Local can be accessed from a method of class stmt16503 by using the name stmt16503_a$1$Local. To reproduce the bug classes should be compiled in sequence - stmt16503_a.java, then stmt16503.java. Compiler correctly detects the error when classes are compiled together. The execution log is following: $ jdk1.4.0beta-b62/solsparc/bin/java -version java version "1.4.0-beta" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b62) Java HotSpot(TM) Client VM (build 1.4.0-beta-b62, mixed mode) $ jdk1.4.0beta-b62/solsparc/bin/javac -d . stmt16503_a.java stmt16503.java; echo $? stmt16503.java:3: cannot resolve symbol symbol : class stmt16503_a$1$Local location: class stmt16503 Object a = new stmt16503_a$1$Local(); ^ 1 error 1 $ jdk1.4.0beta-b62/solsparc/bin/javac -d . stmt16503_a.java; echo $? 0 $ jdk1.4.0beta-b62/solsparc/bin/javac -d . stmt16503.java; echo $? 0 $ jdk1.4.0beta-b62/solsparc/bin/java stmt16503; echo $? 0 $ ======================================================================
|