fork download
  1. import java.lang.invoke.MethodHandles;
  2. import java.lang.invoke.MethodType;
  3.  
  4. class Tmp {
  5. public static void main(String[] args) throws Throwable {
  6. Object[] methodArgs = { "hello", 42 };
  7.  
  8. var mh = MethodHandles.lookup()
  9. .findVirtual(Tmp.class, "method", MethodType.methodType(void.class, String.class, int.class));
  10.  
  11. mh = mh.asSpreader(Object[].class, mh.type().parameterCount() - 1);
  12.  
  13. mh.invokeExact(new Tmp(), methodArgs);
  14. }
  15.  
  16. public void method(String s, int i) {
  17. System.out.println("Tmp.method(): " + s + ", " + i);
  18. }
  19. }
  20.  
Success #stdin #stdout 0.17s 54180KB
stdin
Standard input is empty
stdout
Tmp.method(): hello, 42