Move tests for LambdaMetafactory to source tree
This commit is contained in:
parent
eb6c2538b5
commit
b0326536c7
|
@ -25,14 +25,15 @@ public class Main {
|
|||
String[] newArgs = new String[args.length - 1];
|
||||
System.arraycopy(args, 1, newArgs, 0, args.length - 1);
|
||||
|
||||
Method mainMethod = Class.forName(args[0]).getMethod("main", String[].class);
|
||||
Class<?> mainClass = Class.forName(args[0]);
|
||||
Method mainMethod = mainClass.getMethod("main", String[].class);
|
||||
MethodHandles.Lookup lookup = MethodHandles.lookup();
|
||||
@SuppressWarnings("ConfusingArgumentToVarargsMethod") Runnable main = (Runnable) LambdaMetafactory.metafactory(
|
||||
lookup,
|
||||
"run",
|
||||
MethodType.methodType(Runnable.class, String[].class),
|
||||
MethodType.methodType(Void.TYPE),
|
||||
MethodHandles.lookup().unreflect(mainMethod),
|
||||
lookup.unreflect(mainMethod),
|
||||
MethodType.methodType(Void.TYPE)
|
||||
).getTarget().invokeExact(newArgs);
|
||||
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package io.gitlab.jfronny.inceptum.launchwrapper.test;
|
||||
|
||||
import java.lang.invoke.*;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class InvokeTest {
|
||||
public static void main(String[] args) throws Throwable {
|
||||
Class<?> klazz = TestClass.class;
|
||||
Method mainMethod = klazz.getMethod("main", String[].class);
|
||||
MethodHandles.Lookup lookup = MethodHandles.lookup();
|
||||
|
||||
String[] yes = new String[] {"Shesh"};
|
||||
Runnable main = (Runnable) LambdaMetafactory.metafactory(
|
||||
lookup,
|
||||
"run",
|
||||
MethodType.methodType(Runnable.class, String[].class),
|
||||
MethodType.methodType(Void.TYPE),
|
||||
lookup.unreflect(mainMethod),
|
||||
MethodType.methodType(Void.TYPE)
|
||||
).getTarget().invokeExact(yes);
|
||||
|
||||
new Thread(main).start();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package io.gitlab.jfronny.inceptum.launchwrapper.test;
|
||||
|
||||
public class TestClass {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Yes! " + args[0]);
|
||||
new Throwable().printStackTrace();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue