Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't know, if this is what you really want. Perhaps you could give some more information about what you want to achieve with it. But if you want to access <code>Lookup.IMPL_LOOKUP</code>, you can do it like in this code sample:</p> <pre><code>public class Main { public static void main(String[] args) { Lookup myLookup = MethodHandles.lookup(); // the Lookup which should be trusted NestedTestClass ntc = new Main().new NestedTestClass(); // test class instance try { Field impl_lookup = Lookup.class.getDeclaredField("IMPL_LOOKUP"); // get the required field via reflections impl_lookup.setAccessible(true); // set it accessible Lookup lutrusted = (Lookup) impl_lookup.get(myLookup); // get the value of IMPL_LOOKUP from the Lookup instance and save it in a new Lookup object // test the trusted Lookup MethodHandle pmh = lutrusted.findVirtual(NestedTestClass.class, "gimmeTheAnswer", MethodType.methodType(int.class)); System.out.println(pmh.invoke(ntc)); } catch (Throwable e) { e.printStackTrace(); } } // nested class with private method for testing class NestedTestClass{ @SuppressWarnings("unused") private int gimmeTheAnswer(){ return 42; } } } </code></pre> <p>It works with JDK 7, but could break in JDK 8. And be cautious! My antivirus gave an alarm when I executed it. I think there isn't a public or clean way to do it.</p> <p>I had a similar issue and finally found a solution: <a href="https://stackoverflow.com/questions/16040726/access-non-public-java-native-classes-from-jdk-7">Access non-public (java-native) classes from JDK (7)</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload