⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dynamicproxy.java

📁 动态网站管理发布系统
💻 JAVA
字号:
package com.ntsky.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class DynamicProxy implements InvocationHandler{
  private TestInterface testInterface;
  public DynamicProxy(){
	  testInterface = new Test2();
  }
  
  public TestInterface create(){
	  TestInterface testInterface = null;
	  testInterface = (TestInterface)Proxy.newProxyInstance(TestInterface.class.getClassLoader(),new Class[]{TestInterface.class},this);
	  return testInterface;
  }
  public Object invoke(Object obj,Method method,Object[] args){
	  Object o = null;
	  try {
		System.out.println("方法名="+method.getName());
	    if(method.getName().equals("sayHello")){
		  System.out.println("调用sayHello");
	    }else{
		  o = method.invoke(testInterface,args);
	    }
	  } catch (IllegalArgumentException e) {
		e.printStackTrace();
	  } catch (IllegalAccessException e) {
		e.printStackTrace();
	  } catch (InvocationTargetException e) {
		e.printStackTrace();
	  }	  
	  return o;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -