zoukankan      html  css  js  c++  java
  • 枚举举例

    image

    /**
     * 枚举类型的特点
     * 1、枚举类型有一个公共的基本的父类,是 java.lang.Enum 类型,所以不能再继承别的类型
     * 2、枚举类型的构造器必须是私有的
     * 3、枚举类型可以实现接口
     * 
     * @author kakaluote
     * @date 2021年6月30日 上午9:07:41
     */
    public enum SunFamily {
    
    	SUWUKONG(1,"孙悟空",50,"sunwukong@beijita.sy","1201-02-26"),
    	SUWUFAN(2,"孙悟饭",20,"sunwufan@beijita.sy","1231-05-06"),
    	SUWUTIAN(3,"孙悟天",12,"sunwutian@beijita.sy","1239-10-21"),
    	QIQI(4,"琪琪",47,"qiqi@beijita.com","1204-03-26");
    	
    	private Integer id;
    	private String username;
    	private Integer age;
    	private String email;
    	private String birthday;
    	
    	public static SunFamily getPeople(int index){
    		SunFamily[] sunFamilies = SunFamily.values();
    		for (SunFamily sunFamily : sunFamilies) {
    			if(index == sunFamily.getId()){
    				return sunFamily;
    			}
    		}
    		return null;
    	}
    	
    	public static void main(String[] args) {
    		System.out.println(SunFamily.getPeople(1).getUsername());
    	}
    	//构造器必须私有
    	private SunFamily(Integer id, String username, Integer age, String email,
    			String birthday) {
    		this.id = id;
    		this.username = username;
    		this.age = age;
    		this.email = email;
    		this.birthday = birthday;
    	}
    	
    	public Integer getId() {
    		return id;
    	}
    
    	public String getUsername() {
    		return username;
    	}
    
    	public Integer getAge() {
    		return age;
    	}
    
    	public String getEmail() {
    		return email;
    	}
    
    	public String getBirthday() {
    		return birthday;
    	}
    }
    
  • 相关阅读:
    Vue插件之导出EXCEl
    vue.js--加载JSON文件的两种方式
    vue项目中axios的封装
    雪碧图布局
    开始学习算法
    Java中有关Null的9件事
    一个抓取知乎页面图片的简单爬虫
    浅析Java中的final关键字
    Java中String、StringBuilder以及StringBuffer
    把一个数组向右循环移动k位要求时间复杂度为O(n)
  • 原文地址:https://www.cnblogs.com/kaka-qiqi/p/14952968.html
Copyright © 2011-2022 走看看