Class TestHolder
needs to call the private constructor in Test
. But it's private, and can't actually be called from another class. So the compiler plays a trick. It adds a new non-private constructor to Test
which only it knows about! That constructor takes an (unused) instance of this anonymous class Test$1
-- which nobody knows exists. Then TestHolder
creates an instance of Test$1
and calls that constructor, which is accessible (it's default-protected.)
You can use javap -c Test
(and javap -c Test\$1
, and javap -c Test\$TestHolder
) to see the code. It's quite clever, actually!