首页 > 编程语言 > 详细

java反射获取类属性类型

时间:2016-05-30 02:03:29      阅读:225      评论:0      收藏:0      [点我收藏+]

package Test;

?

/**

?* 通过反射获取类属性的类型

?* @author test

?*

?*/

public class OtherTest {

?

private static int i = 1;

private static String name = "wang";

?

public static void main(String[] args) throws Exception {

?

System.out.println(OtherTest.class.getDeclaredField("i").getType());

System.out.println(OtherTest.class.getDeclaredField("name").getType());??

}

}

?

另:getDeclaredField是可以获取一个类的所有字段.?getField只能获取类的public 字段.

java反射获取类属性类型

原文:http://wangduorong.iteye.com/blog/2301063

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!