一个讨论j2ee技术以及畅谈程序人生的地方,一个有共同兴趣和
龙心客栈 · dragonet · 2004-08-09
一个讨论j2ee技术以及畅谈程序人生的地方,一个有共同兴趣和爱好的朋友相聚的乐园。
|
首页
|
a trick about 'How to update multiple value in collection' on Struts>>>
How to visit those methods which are not public?
时间: 2004-08-09
Today I met a question when I developed Execute Architecture,I need invoke a method 'test()' of a class A,but that method is 'protect',and my class isn't extends class A.what shall I do?Draft a class extends class A?I didn't want to add a class just for a method,my way is as follows:
//If there is an instance 'a' of class A,
Class c=a.getClass();
Method m=c.getDeclaredMethod("test",new Class[] {});
m.setAccessible(true);
Object obj=m.invoke(a,null);
then I got what I want.if there is a secruity manager,we should draft:
ReflectPermission ref=new ReflectPermission("suppressAccessChecks");
dragonet
引用(Trackback0)
评论
It's written all by youself?nice! especially in English.
you can express yourself in English thoroughly. Very good, learn from you...
steve_gu
(
I hava a question about setAccessible.
what's the range of the exxcute of this method.
when and where the
field or method will
resume its access control.
wangy
(
I am not too clear,I will do some tests when I have time.But I think it's only useful for reflect object m.
dragonet
(
dragonet.blogbus.com
发表评论
最后更新
log4j synthetically
How to estimate
a trick about 'How to update multiple value in collection' on Struts
How to visit those methods which are not public?
学习java
八卦1: 瑜珈
Analysis Mechanism
关联类
关于培训的看法
一个小小的技巧,不知swing何时能这样?
原始快照:web.archive.org