Domanda

how compiler knows about nested types like :

  • Nested inner classes
  • Anonymous class
  • Nested Interface

.....etc

Need clearity.......

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top