package com.hra.riskprice; import com.hra.riskprice.SysEnum.Factor_Type; import com.hra.riskprice.pojo.SysEnumDict; import com.sun.corba.se.spi.orb.Operation; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import java.util.*; @SpringBootApplication public class RiskpriceApplication { interface Operation{ double apply(double x,double y); } enum BasicOperation implements Operation { PLUS("+"){ public double apply(double x, double y) { return x+y; } }, MINUS("-"){ public double apply(double x, double y) { return x-y; } }, TIMS("*"){ public double apply(double x, double y) { return x*y; } }, DIVIDE("/"){ public double apply(double x, double y) { return x/y; } }; private final String symbol; BasicOperation(String symbol){ this.symbol=symbol; } @Override public String toString() { return symbol; } } public static void main(String[] args) { BasicOperation b; b=BasicOperation.PLUS; Integer[] ids= Integer.class.getEnumConstants(); test(BasicOperation.class,1,3);//主要方法 下面是获取枚举集合的列举方法 EnumSet<BasicOperation> ops= EnumSet.allOf(BasicOperation.class);//在java中为枚举专门设计 效率高 第一名 BasicOperation[] op2s= BasicOperation.values();//效率没有EnumSet高 第二名 BasicOperation[] op1s= BasicOperation.class.getEnumConstants(); //如果不是枚举返回空 任何类型都点的出来 注意用到了.class 第三名 } private static <T extends Enum<T> & Operation> void test(Class<T> opSet,double x,double y){ for(Operation op:opSet.getEnumConstants()){ System.out.println(x+" "+op +" "+ y+" ="+op.apply(x,y)); } } }