Java代码  Reflection的getCallerClass静态方法
  1. package com.huangyunbin;  
  2.   
  3. import sun.reflect.Reflection;  
  4.   
  5. public class Test  
  6. {  
  7.     public static void main(String[] args)  
  8.     {  
  9.         Test2 test=new Test2();  
  10.         test.g();  
  11.     }  
  12. }  
  13.   
  14.   
  15.  class Test2  
  16. {  
  17.     public  void g(){  
  18.         gg();  
  19.     }  
  20.     public  void gg(){  
  21.         System.out.println(Reflection.getCallerClass(-1));  
  22.         System.out.println(Reflection.getCallerClass(0));  
  23.         System.out.println(Reflection.getCallerClass(1));  
  24.         System.out.println(Reflection.getCallerClass(2));  
  25.         System.out.println(Reflection.getCallerClass(3));  
  26.         System.out.println(Reflection.getCallerClass(4));  
  27.         System.out.println(Reflection.getCallerClass(5));  
  28.     }  
  29.   
  30. }  


输出结果是: 
Java代码  Reflection的getCallerClass静态方法
  1. class sun.reflect.Reflection  
  2. class sun.reflect.Reflection  
  3. class com.huangyunbin.Test2  
  4. class com.huangyunbin.Test2  
  5. class com.huangyunbin.Test  
  6. class com.intellij.rt.execution.application.AppMain  
  7. null  

相关文章:

  • 2022-12-23
  • 2022-02-09
猜你喜欢
  • 2021-12-17
  • 2022-12-23
  • 2022-02-09
  • 2021-12-15
  • 2022-12-23
相关资源
相似解决方案