There's quite enough detail here.
You're supposed to get an IllegalAccessException, that's what 'private' does. If you need to do this you need the appropriate RuntimePermission and you need to call Method.setAccessible(): see [url]http://java.sun.com/j2se/1.5.0/docs/api/java/lang/reflect/AccessibleObject.html#setAccessible(java.lang.reflect.AccessibleObject[],%20boolean)[/url].
> There's quite enough detail here.
Well, I read the subject literally and triedclass Test {
public static final void main(String[] arg) {
Test test = new Test();
test.run();
}
Test() {}
void run() {
Foo foo = new Foo();
System.out.println(String.valueOf(foo));
}
private class Foo {
private Foo() {}
}
}
and it did not give any exceptions.
> Well 'private' does have a well-known meaning in
> Java, and it's been working in Java for at least 11
> years. Surely you knew that?
The combination "private class" seemed unusual
and made me de-focus from the rest of it.
> Re your example, special rules apply to inner
> classes. The access modifiers aren't tested by the
> enclosing class.
Yes. The only way I am aware of of having a "private class" (as the subject implies) is to have a nested class.
I agree one would be able to access methods on an instance of such a class only from the embedding class (or peer nested classes).