这个有什么用吗?还是说想脑筋体操一把?-------- With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead.
我跟你打赌 AOP 解决不了这个问题 :)这个问题理论上是有解的,但前提是编译时保留了调试信息,否则神仙也没辙。-------- With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead.
这个事情要靠文档啊,怎么想到反射去了?!-------- With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead.
With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is
hard to be sure where they are going to land, and it could be dangerous sitting under them as they
fly overhead.
With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is
hard to be sure where they are going to land, and it could be dangerous sitting under them as they
fly overhead.
aop就是代理耶: 当然分为:编译时增强和运行时增强(cglib或jdk 动态代理)
■□■□■□■□■□■□■□■
□ □
■ 忍以明志 勤以致远 ■
□ □
■□■□■□■□■□■□■□■
基于CSDN论坛提供的插件扩展功能,自己做了个签名档工具,分享给大家,欢迎技术交流 :)
确实是这样,不过,你要获得干嘛?
你方法写好了,公布个API,那时参数名已经写好在代码里面,那么还要再获得???
With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is
hard to be sure where they are going to land, and it could be dangerous sitting under them as they
fly overhead.
………………
我彻底无语,公布API就好了,API就是给别人看的文档,给别人去调用
我当时也有想获取文档的信息,但也不知道怎样去获取,请教这位仁兄有什么方法去获取得到?
如,获取resName 资源名称和operateKey 操作类型:/**
* 根据资源名和操作类型来获取资源ID
* @author CaiJiuFa
* @param resName 资源名称
* @param operateKey 操作类型
* @return 资源ID列表
*/
public static String getRecourceOfCurrentUser(String resName, String operateKey) {}
□ □
■ 忍以明志 勤以致远 ■
□ □
■□■□■□■□■□■□■□■
基于CSDN论坛提供的插件扩展功能,自己做了个签名档工具,分享给大家,欢迎技术交流 :)
import java.lang.reflect.Field;
import java.lang.reflect.Method;public class getRecourceOfCurrentUser {
public static void main(String[] args) throws Exception {
reflect rl = new reflect();
Class cla = reflectT.class;
Field[] field = cla.getDeclaredFields();
Method[] methods = cla.getDeclaredMethods();
for (Method method : methods) {
if (method.getName() == "reflect1") {
System.out.println(method.getName());
for (Field field2 : field) {
System.out.print(field2.getType() + " " + field2.getName()
+ " " + "\n");
} }
} }}class reflect { public static String reflect1(String resName, String operatekey) {
return operatekey; }}
import java.lang.reflect.Field;
import java.lang.reflect.Method;public class getRecourceOfCurrentUser { public static void main(String[] args) throws Exception {
Class cla = reflectT.class;
Field[] field = cla.getDeclaredFields();
Method[] methods = cla.getDeclaredMethods();
for (Method method : methods) {
if (method.getName() == "reflect1") {
System.out.println(method.getName());
for (Field field2 : field) {
System.out.print(field2.getType() + " " + field2.getName()
+ " " + "\n");
} }
} }}class reflectT { private String resName;
private String operatekey; public String getResName() {
return resName;
} public void setResName(String resName) {
this.resName = resName;
} public String getOperatekey() {
return operatekey;
} public void setOperatekey(String operatekey) {
this.operatekey = operatekey;
} public static String reflect1(String resName, String operatekey) {
return operatekey; }}
这应该要看模块开发者写的API文档,光从变量名里看是不现实的变量名不见得能体现参数的意义,比如有的人把参数名写成 arg1, arg2, arg3 这类形式领导提个建议罢了,如果强制你这样做,那就是瞎指挥。
1.使用javassist.jar 这个项目可以帮助你解决这个问题,它是一个增强的反射工具。
项目地址http://www.csg.is.titech.ac.jp/~chiba/javassist/
使用例子http://www.blogjava.net/Hafeyang/archive/2010/10/25/using_powerful_java_reflect_tool_javassist_to_getParameterAnnotations_and_getParameterNames.html
但是这个工具的运行效率没有ASM高。你也可以使用ASM来扫描Class文件这样获取你要的属性名,前提是你需要对 Class字节码有比较深入的了解。我更趋向于使用后者,但是ASM的API没有javassist方便。