import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
/**
* Created by BaiJiFeiLong@gmail.com at 2018/4/17 11:15
*/
public class App {
interface HiService {
String hi(String name);
}
public static void main(String[] args) {
proxy();
}
private static void proxy() {
HiService hiService = (HiService)Proxy.newProxyInstance(
App.class.getClassLoader(),
new Class[]{HiService.class},
new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) {
return "Hi ~ " + args[0];
}
});
String str = hiService.hi("world");
System.out.println("str = " + str);
}
}