public enum ProductLine {
DAMAO(“大猫”, 1),
DABAO(“大宝”, 2);
private String description;
private Integer code;
public static ProductLine of(Integer code) {
Objects.requireNonNull(code);
return Stream.of(***values()***).filter(***bean -> bean.code.equals(code)***)
.findAny()
.orElseThrow(() -> new IllegalArgumentException(code + " not exists! "));
}
}
第二个表达式可以理解为需要一个异常对象就传递了个创建对象的过程
第一个Lambda 表达式没有看懂,为什么能用bean来代替枚举类例的枚举?这个values()也不大能理解这个写法.
Stream.of()是利用泛型直接返回一个枚举对象吗?