package com.zhen.aop1;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class Test {
/**
* @param args
* @throws IllegalAccessException
* @throws InstantiationException
* @throws ClassNotFoundException
* @throws NoSuchMethodException
* @throws SecurityException
* @throws InvocationTargetException
* @throws IllegalArgumentException
*/
public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException {
// TODO Auto-generated method stub
//静态代理 要明确代理的对象是那个,执行什么代码
// IHello hello = new HelloProxy(new HelloImpl());
// hello.sayHello("Doublej");
//动态代理 不需明确代理类 无需编写源代码
//1接口类 2实现类 3 代理类 注意 代理类需要实现InvocationHandler接口,创建初始化代理类
IHello hello = (IHello) new DynaProxy().bind(new HelloImpl());
hello.sayHello("Double J");
// Class<?> forName = Class.forName("com.zhen.test.HelloImpl");
// Method method = forName.getDeclaredMethod("sayHello", String.class);
// Method method = forName.newInstance().getClass().getMethod("sayHello", String.class);
// method.invoke(forName.newInstance(), "Mine");
// try {
//
// Class cls= Class.forName("com.zhen.test.HelloImpl");
// Method method=cls.getDeclaredMethod("sayHello",new Class[] {String.class });
// HelloImpl helloImpl = (HelloImpl)cls.newInstance();
// method.invoke(helloImpl, new Object[] { "aa" });
// } catch (ClassNotFoundException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (SecurityException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (NoSuchMethodException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (IllegalArgumentException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (InvocationTargetException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
}
}
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class Test {
/**
* @param args
* @throws IllegalAccessException
* @throws InstantiationException
* @throws ClassNotFoundException
* @throws NoSuchMethodException
* @throws SecurityException
* @throws InvocationTargetException
* @throws IllegalArgumentException
*/
public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException {
// TODO Auto-generated method stub
//静态代理 要明确代理的对象是那个,执行什么代码
// IHello hello = new HelloProxy(new HelloImpl());
// hello.sayHello("Doublej");
//动态代理 不需明确代理类 无需编写源代码
//1接口类 2实现类 3 代理类 注意 代理类需要实现InvocationHandler接口,创建初始化代理类
IHello hello = (IHello) new DynaProxy().bind(new HelloImpl());
hello.sayHello("Double J");
// Class<?> forName = Class.forName("com.zhen.test.HelloImpl");
// Method method = forName.getDeclaredMethod("sayHello", String.class);
// Method method = forName.newInstance().getClass().getMethod("sayHello", String.class);
// method.invoke(forName.newInstance(), "Mine");
// try {
//
// Class cls= Class.forName("com.zhen.test.HelloImpl");
// Method method=cls.getDeclaredMethod("sayHello",new Class[] {String.class });
// HelloImpl helloImpl = (HelloImpl)cls.newInstance();
// method.invoke(helloImpl, new Object[] { "aa" });
// } catch (ClassNotFoundException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (SecurityException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (NoSuchMethodException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (IllegalArgumentException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (InvocationTargetException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
}
}