forked from Jossc/JavaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFoo.java
More file actions
27 lines (23 loc) · 739 Bytes
/
Foo.java
File metadata and controls
27 lines (23 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package com.jvm.bytecode;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
/**
* @ClassName Foo
* @Author chenzhuo
* @Version 1.0
* @Date 2019-07-28 21:28
**/
public class Foo {
public void print(String s) {
System.out.println("hello :" + s);
}
public static void main(String[] args) throws Throwable {
Foo foo = new Foo();
System.out.println(void.class.getClassLoader());
MethodType methodType = MethodType.methodType(void.class,String.class);
MethodHandle methodHandle = MethodHandles.lookup().
findVirtual(Foo.class, "print", methodType);
methodHandle.invokeExact(foo, "world");
}
}