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

枚举应用三

时间:2015-08-10 19:41:58      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

枚举实现的接口

技术分享
 1 package com.yeepay.sxf.euma;
 2 /**
 3  * 枚举接口类
 4  * @author sxf
 5  *
 6  */
 7 public interface SuprtEuma {
 8     /**
 9      * 输入值获取当前枚举的字符串
10      * @param integer
11      * @return
12      */
13     public String getIndex(Integer integer);
14 }
View Code

枚举类

技术分享
 1 package com.yeepay.sxf.euma;
 2 /**
 3  * 枚举实现接口的枚举类
 4  * @author sxf
 5  *
 6  */
 7 public enum Diest implements SuprtEuma{
 8     
 9     HSL("黄栓磊",26),
10     SXF("尚晓飞",27),
11     QCF("瞿成峰",28);
12 
13     private String name;
14     private Integer age;
15     
16     private Diest(String name,Integer age) {
17         this.name=name;
18         this.age=age;
19     }
20     
21     /**
22      * 重写接口方法
23      */
24     @Override
25     public  String getIndex(Integer integer) {
26         Diest[] de=Diest.values();
27         for (Diest diest : de) {
28             Integer age=diest.getAge();
29             if(age==integer){
30                 return diest.getName();
31             }
32         }
33         
34         return null;
35     }
36     public String getName() {
37         return name;
38     }
39     public void setName(String name) {
40         this.name = name;
41     }
42     public Integer getAge() {
43         return age;
44     }
45     public void setAge(Integer age) {
46         this.age = age;
47     }
48 
49     
50     
51     
52 }
View Code

枚举测试类

技术分享
 1 package com.yeepay.sxf.euma;
 2 
 3 
 4 public class Test {
 5     public static void main(String[] args) {
 6         test3();
 7     }
 8     
 9     public static void test3(){
10         String nameString=Diest.HSL.getIndex(26);
11         System.out.println("Test.test3()"+nameString);
12     }
13     
14 }
View Code

测试结果

Test.test3()黄栓磊

枚举应用三

标签:

原文地址:http://www.cnblogs.com/shangxiaofei/p/4718890.html

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