被调用对象的方法内部,如何"动态"获得调用者(调用对象)的引用。
被调用对象的方法内部,如何"动态"获得调用者(调用对象)的引用。
如题:
class A{ f1(){ B.f2() }}class B{ static f2(){ //这里如何动态获得 调用者的引用。 }}
public static String getCaller(){int i;StackTraceElement stack[] = (new Throwable()).getStackTrace();for (i=0; i < stack.length; i++) {StackTraceElement ste=stack[i];System.out.println(ste.getClassName()+"."+ste.getMethodName()+"(...)");System.out.println(i+"--"+ste.getMethodName());System.out.println(i+"--"+ste.getFileName());System.out.println(i+"--"+ste.getLineNumber());}}
[解决办法]
只知道JAVA里 楼主这种要求 都不是用JAVA语言写的