枚举和反射

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)相关的事物

image

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

转载于:https://my.oschina.net/jiemoxiaodi/blog/848220

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值