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

枚举和反射

时间:2015-12-31 01:37:10      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

enum

 

package cn.jiemoxiaodi_enum;

public class School {
    public static School s1=new School("北1京", "1sdfds");
    public static School s2=new School("北京2", "2sdfds");
    public static School s3=new School("北京3", "3sdfds");
    
    
    private String name;
    private String teacher;

    @Override
    public String toString() {
        return "School [name=" + name + ", teacher=" + teacher + "]";
    }

    private School() {
        super();
    }

    private School(String name, String teacher) {
        super();
        this.name = name;
        this.teacher = teacher;
    }
}

---

package cn.jiemoxiaodi_enum;

public enum School2 {

    shanghai("比较", "sdf"), bj("3", "44"), sz("55", "dfd"), hz("sdf", "sdf");

    private School2(String name, String ordinal) {
    }
    
}

 

int  short enum

枚举中可以 用在switch  枚举中必须的进行相关的(abstract  Method)实现

 

反射

万物都是对象:

java=>编译器=》class ==类加载器=》jvm—>

反射就是用来描述与字节码(class)相关的事物

技术分享

package cn.jiemoxiaodi.reflect;

import java.io.FileInputStream;
import java.util.Properties;

import org.junit.Test;

public class UserDaoTest {

    /**
     * @param args
     * @throws Exception 
     * 
     */
    @Test
    public void testUserDao() throws Exception {
        
        Properties pro=new Properties();
        pro.load(new FileInputStream("src/cn/jiemoxiaodi/reflect/beanname.properties"));
        
        String str=pro.get("UserDao").toString();
        Class c1 = Class.forName(str);
        UserDao ud=(UserDao) c1.newInstance();
        ud.save();
    }
}

构造函数 constructor

方法  method

字段  fields

枚举和反射

标签:

原文地址:http://www.cnblogs.com/jiemoxiaodi/p/5090424.html

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