点击这里给我发消息 点击这里给我发消息

JVM技术,反射与动态代理

添加时间:2013-12-7
    相关阅读: 技术 Access

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.

}

}

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.

}

}

 

[1] [2] 下一页

咨询热线:020-85648757 85648755 85648616 0755-27912581 客服:020-85648756 0755-27912581 业务传真:020-32579052
广州市网景网络科技有限公司 Copyright◎2003-2008 Veelink.com. All Rights Reserved.
广州商务地址:广东省广州市黄埔大道中203号(海景园区)海景花园C栋501室
= 深圳商务地址:深圳市宝源路华丰宝源大厦606
研发中心:广东广州市天河软件园海景园区 粤ICP备05103322号 工商注册