码迷,mamicode.com
首页 > 其他好文 > 详细

反射机制--获取类的方法

时间:2016-12-21 14:01:50      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:except   ext   row   public   属性   --   throw   机制   color   

一、反射机制获取一个类的方法

  1.使用class属性

    类名.class

  2.使用Class类的forName(“类名”)方法,

    Class.forName("类名")

  3.new一个类然后调getClass()方法

    new 类名().getClass()

实例:

public void text() throws ClassNotFoundException{
        //第一种方式
        Class cla = Integer.class;
        //第二种方式
        Class cla2 = Class.forName("Integer");
        //第三种方法
        Class cla3 = new Integer(0).getClass();
        
    }

 未完待续。。。。

反射机制--获取类的方法

标签:except   ext   row   public   属性   --   throw   机制   color   

原文地址:http://www.cnblogs.com/zbrave/p/6207404.html

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