Duplicate :
|
|
Duplicate :
|
|
Duplicate :
|
|
Duplicate :
|
|
Duplicate :
|
|
Duplicate :
|
|
Duplicate :
|
|
Duplicate :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
Name: sg39081 Date: 08/14/97 Running the following program, which should succeed, results in an IllegalAccessException. import java.lang.reflect.*; public class TestPrivateAccess extends Object { TPAInnerClass inner = new TPAInnerClass(); private void privateMethod() {System.out.println("private method.");} class TPAInnerClass extends Object { void dynamicInvoke() { try { Method method = TestPrivateAccess.class.getDeclaredMethod("privateMethod", new Class[] {}); method.invoke(TestPrivateAccess.this, new Object[] {}); } catch (Exception e) {e.printStackTrace();} } } public static void main(String[] argv) { TestPrivateAccess tpa = new TestPrivateAccess(); tpa.inner.dynamicInvoke(); } } company - MIT Media Lab , email - ###@###.### ======================================================================
|