Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is "inner class emulation" in Java?

just found this bit, while reading eclipse JDT's documentation:

IMethodBinding.getParameterTypes(): . . . Note: The result does not include synthetic parameters introduced by inner class emulation.

I can't find any reference to inner class emulation in JLS... Anyone knows what this emulation is? Throwing an example, would help as well. :)

like image 804
John Assymptoth Avatar asked Dec 18 '10 04:12

John Assymptoth


1 Answers

I think that the Eclipse documentation writer being a little bit loose with the terminology. As far as the JLS is concerned, an inner class is an inner class and doesn't need to be emulated.

However, there is a bit of trickiness in the way that inner classes get implemented by a typical JVM, and this is where the synthetic constructor parameters come into the equation. What is going on is that the JVM implements classes the same whether they are nested or not. There are no special bytecodes for referring to variables in enclosing classes, so the compilers generate code that fetch them via the synthetic attributes.

More details may be found in the original Sun Java 1.1 Inner Classes Specification.

like image 179
Stephen C Avatar answered Sep 29 '22 10:09

Stephen C