Java 找到某个方法的调用者类.

public class Caller {
	public static void main(String[] args) {
		System.setSecurityManager(new MySecurityManager());
		new A().method();
	}
}

class MySecurityManager extends SecurityManager {
	protected Class[] getClassContext() {
		return super.getClassContext();
	}
};

class A {
	void method() {
		new B().method();
	}
}

class B {
	void method() {
		MySecurityManager sm = (MySecurityManager) System.getSecurityManager();
		Class[] cls = sm.getClassContext();
		// for(int i=0;i<cls.length;i++) System.out.println(cls[i]);
		System.out.println(cls[2] + "   is   Calling   me");
	}
}

 


   

你可能感兴趣的:(java,thread,C++,c,C#)