比如一个类中有一个函数 void functionName() {
callOtherFunction("functionName");
}有没有办法取得函数名称字符串呢?在callOtherFunction如果不通过指定的字符串传递能知道调用者是哪个函数吗?
callOtherFunction("functionName");
}有没有办法取得函数名称字符串呢?在callOtherFunction如果不通过指定的字符串传递能知道调用者是哪个函数吗?
解决方案 »
- Could not find the main class Program will exit 解决方案
- javaNIO的问题。。
- JDBC插入大量数据优化
- 关于图片上传时自动生成缩略图的问题~~Can't read input file!错误---急~~
- public Graphics getGraphics()为组件创建一个图形上下文 是什么意思??
- 如何删除文件中指定的数据
- 终于又有10分了 超级菜鸟再问个问题 简单绝对
- 再不用看人脸色,认证资料下载(PDF格式,13套)
- 如何显示汉字
- java能不定义常量
- 一个SCJP考试认证的问题,哪位大侠可以帮我解释一下啊!
- 多个线程同时写一个文件,该怎么做?
http://www.itpub.net/viewthread.php?tid=959000
我对这个也不是非常熟悉,但是,要取得函数名称是可以的。一个类中所包含的函数信息都可以获取。同时还可以与元数据结合使用。其他的,你先研究,研究明白了教给我哈~~
try{
throw Exception("");
}catch(Exception ex){
//分析ex的信息,截取本函数的方法名
callOtherFun(parseFunName(ex.toString()));
}
}
test(Thread.currentThread().getStackTrace()[1].getMethodName());
} public static void test(String s) {
System.out.println(s);
} public static void main(String[] args) {
methodForTest();
}}
StackTraceElement[] stes = t.getStackTrace();
for(int i=0;i<stes.length;i++){
System.out.println(stes[i].getClassName() + "类" + stes[i].getMethodName() + "方法 第" + stes[i].getLineNumber) +"行";
}
{
public static void main(String[]arr)
{Classname a=new Classname();
System.out.println(a.toString());}
public String toString(){return"Classname";}
}