fork download
  1. import sun.misc.Unsafe;
  2. import java.lang.invoke.MethodHandle;
  3. import java.lang.invoke.MethodHandles;
  4. import java.lang.invoke.MethodType;
  5. import java.lang.reflect.Field;
  6.  
  7. class Test {
  8.  
  9. public static void main(String[] args) throws Throwable {
  10. Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
  11. theUnsafe.setAccessible(true);
  12. Unsafe unsafe = (Unsafe) theUnsafe.get(null);
  13.  
  14. Field impl_lookup = MethodHandles.Lookup.class.getDeclaredField("IMPL_LOOKUP");
  15. MethodHandles.Lookup lookup = (MethodHandles.Lookup) unsafe.getObject(unsafe.staticFieldBase(impl_lookup), unsafe.staticFieldOffset(impl_lookup));
  16.  
  17. MethodHandle constructor = lookup.findConstructor(Void.class, MethodType.methodType(void.class));
  18. Void v = (Void)constructor.invokeExact();
  19.  
  20. System.out.println(v);
  21. }
  22. }
  23.  
Success #stdin #stdout 0.09s 33636KB
stdin
Standard input is empty
stdout
java.lang.Void@65b54208