Tuesday, April 12, 2016

How the compiler understands your Java class


I have the following static factory method that creates a list view out of an int array: In "Effective Java", Joshua Bloch mentioned this as an
Adapter that allows an int array to be viewed as a list of Integer instances
However, I remember that Adapter pattern uses composition and the instance of the anonymous list implementation should therefore use the int[] as a member field. To verify the hypothesis and understand how the class is understood by the compiler, one can use the following command:
javac -d . -XD-printflat ListFactory.java
From the output, one can clearly understand how the final parameter is passed to the inner anonymous class implementation: