![]() |
Sponsored Link •
|
Advertisement
|
Advertisement
|
This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.
Message:
(delete "antispam" from the domain name above to obtain my true email address) Can anyone explain to me the strange treatment by the JDK 1.3 javac compiler of a static nested class with a private constructor? An unexpected, apparently local, class file is compiled from the sample code shown below: class Outer A file Outer$1.class is created in addition to the expected Outer.class and Outer$Nested.class. The compiler does not generate Outer$1.class if the private access modifier is deleted from the Nested constructor declaration as follows: class Outer When the Nested constructor is declared private, a disassembly ---- disassembly of Outer$Nested (private constructor) ---- Compiled from Outer.java Method Outer. Nested() Line numbers for method Outer. Nested() Method Outer. Nested(Outer$1) Line numbers for method Outer. Nested(Outer$1) --- end disassembly of Outer$Nested (private constructor) --- A disassembly of Outer.class contains the following entry 9 invokespecial #3 A disassembly of Outer$1 shows it to be an empty class: Compiled from Outer.java When the Nested constructor has package access, ---- disassembly of Outer$Nested (package constructor) ---- Compiled from Outer.java Method Outer. Nested() Line numbers for method Outer. Nested() --- end disassembly of Outer$Nested (package constructor) --- When the Nested constructor has package access, 8 invokespecial #3 Why this strange distinction between public and private |
Sponsored Links
|