码迷,mamicode.com
首页 > 编程语言 > 详细

Java Reflection类

时间:2018-06-18 16:10:12      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:nbsp   col   img   get   gif   oid   new   分享图片   tca   

Reflection类

getCallerClass()。返回调用者Class对象。
例如:
技术分享图片
 1 public class Test1 {
 2     public void mthod1() {
 3         Class clazz = Reflection.getCallerClass();
 4         System.out.println("test1调用方法:"+clazz.getSimpleName());
 5         new Test2().test2();
 6     }
 7 }
 8 
 9 class Test2{
10     public void test2() {
11         Class clazz = Reflection.getCallerClass();
12         System.out.println("test2调用方法:"+clazz.getSimpleName());
13     }
14     public static void main(String[] args) {
15         new Test1().mthod1();
16     }
17 }
18 输出:
19 test1调用方法:Test2
20 test2调用方法:Test1
View Code

 

Java Reflection类

标签:nbsp   col   img   get   gif   oid   new   分享图片   tca   

原文地址:https://www.cnblogs.com/hf-china/p/9195263.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!