| 网管联盟 | 网管论坛 | 网管u家 | 网管博客 | 网管软件 | 网管求职 | 小游戏 | 网管搜索 | 网管原创 | 网管聚合 | 网管读摘 | 网管焦点 | 世界素材 | 会员投稿 | 会员中心 |
![]() |
| Windows Linux Cisco 网络技术 数据库 黑客攻防 DotNet Java PHP 认证 新闻资讯 服务器 存储资讯 网络设备 网管学堂 技术专题 焦点 网吧频道 |
|
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
import java.io.IOException;
public class Main {
public static void main(String[] args){
TempImpl t1 = new TempImpl("temp1");
try {
Method t1Talk = t1.getClass().getMethod("Talk", new Class[0]) ;
t1Talk.invoke(t1, null);
} catch (NoSuchMethodException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} catch (IllegalAccessException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} catch (InvocationTargetException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
try {
System.in.read();
} catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
}
|
|
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
import java.io.IOException;
public class Main {
public static void main(String[] args){
TempImpl t1 = new TempImpl("temp1");
TempImpl t2 = new TempImpl("temp2");
Temp2 temp2 = new Temp2();
try {
Method t1Talk = t1.getClass().getMethod("Talk", new Class[0]) ;
Method t2Talk = t2.getClass().getMethod("Talk", new Class[0]) ;
t1Talk.invoke(t2, null);
t2Talk.invoke(t1, null);
if(t1Talk.equals(t2Talk)){
System.out.println("equals");
}
else{
System.out.println("not equals");
}
if(t1Talk==t2Talk){
System.out.println("ref equals");
}
else{
System.out.println("ref not equals");
}
t2Talk.invoke(temp2, null);
} catch (NoSuchMethodException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} catch (IllegalAccessException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} catch (InvocationTargetException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
try {
System.in.read();
} catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
}
|
|
0
|
评论加载中…