- package com.huangyunbin;
- import sun.reflect.Reflection;
- public class Test
- {
- public static void main(String[] args)
- {
- Test2 test=new Test2();
- test.g();
- }
- }
- class Test2
- {
- public void g(){
- gg();
- }
- public void gg(){
- System.out.println(Reflection.getCallerClass(-1));
- System.out.println(Reflection.getCallerClass(0));
- System.out.println(Reflection.getCallerClass(1));
- System.out.println(Reflection.getCallerClass(2));
- System.out.println(Reflection.getCallerClass(3));
- System.out.println(Reflection.getCallerClass(4));
- System.out.println(Reflection.getCallerClass(5));
- }
- }
输出结果是:
- class sun.reflect.Reflection
- class sun.reflect.Reflection
- class com.huangyunbin.Test2
- class com.huangyunbin.Test2
- class com.huangyunbin.Test
- class com.intellij.rt.execution.application.AppMain
- null