Reflection的getCallerClass的使用:可以得到调用者的类.这个方法是很好用的.
0 和小于0 - 返回 Reflection类
1 - 返回自己的类
2 - 返回调用者的类
3. 4. ....层层上传。
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
分享到:
相关推荐
Exploiting Reflection Change for Automatic Reflection Removal.去除像反光
Java Reflection in Action is unique in presenting a clear account of all the cool things you can do with reflection, and at the same time pro- viding the sound conceptual basis that developers need to...
Unity Planar Reflection平面反射
例如,使用它能获得 Java 类中各成员的名称并显示出来。 Java 的这一能力在实际应用中也许用得不是很多,但是在其它的程序设计语言中根本就不存在这一特性。例如,Pascal、C 或者 C++ 中就没有办法在程序中获得函数...
java reflection in action 2005 英文版
JAVA REFLECTION IN ACTION
Tracking radar targets with multiple reflection points
Managed.Reflection, System.Reflection [.Emit ]的托管替换 Managed.ReflectionManaged.Reflection 是对 System.Reflection 和 System.Reflection.Emit的完全管理的替换。 System.Reflection 不同,它不绑定到
C#反射(Reflection)详解 什么是反射 命名空间和装配体的关系
让你轻松搞定Reflection(反射)
Laravel开发-reflection 模块说明
java reflection 内容学习
C#例子代码 A0006_Reflection2C#例子代码 A0006_Reflection2C#例子代码 A0006_Reflection2C#例子代码 A0006_Reflection2C#例子代码 A0006_Reflection2C#例子代码 A0006_Reflection2C#例子代码 A0006_Reflection2C#...
reflection的ppt介绍,当中包括大学课程reflection的详细讲解
详细解说reflection 和annotation
B4A Reflection Library