我有以下类(注意方法是静态的):
class Base { public static void whosYourDaddy() { Class callerClass = // what should I write here to get caller class? System.out.print(callerClass.getName()); } } Class A extends Base { public static void foo() { A.whosYourDaddy(); } } Class B extends Base { public static void bar() { B.whosYourDaddy(); } }
当我打电话时:
A.foo(); B.bar();