Prateek
Prateek

Reputation: 12252

How the compiler and runtime system deal with nested types in java?

how compiler knows about nested types like :

.....etc

Need clearity.......

Upvotes: 1

Views: 105

Answers (1)

AlexR
AlexR

Reputation: 115378

Compiler extracts inner classes and creates separate *class file for each one. Inner class name is created as OuterClassName$InnerClassName. Anonymous inner classes do not have names, so their names are created as OuterClassName$1, OuterClassName$2, etc.

Inner classes have special reference to instance of outer class using syntax OuterClassName.this.

Since inner classes are compiled into separate class files JVM does not deal with inner classes at all. It deals with regular classes that have "special" names described above.

Upvotes: 6

Related Questions