Suppose a test class contains a static inner class Dog, which it instantiates and makes bark.
Everything works, even if I instantiate a Dog in the over-complicated fashion of line 7.
Assuming that class can access its own private members, I was expecting this to work exactly the same if Dog is declared private, but that's not the case. The code compiles, but throws an IllegalAccessException.
So, is it not true to say, without qualification, that a class can access it's own private members?
Stephan van Hulst wrote:You're asking Class to access it, and Dog is not a private member of Class.
Trying to think that through, Class is in java.lang, a different package from PrivateTest1 and I didn't declare the static nested class Dog as public, so from the perspective of java.lang.Class, even in my PrivateTest1 example, Dog shouldn't be visible.
This might involve a deeper enquiry into the workings of java.lang.Class than I need for practical purposes