枚举实现的接口
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 }
枚举类
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 }
枚举测试类
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 }
测试结果
Test.test3()黄栓磊