优雅枚举之枚举回调

@Getter
@AllArgsConstructor
public enum FunctionEnum {

    CHECK(1, "是否预期", t -> 2 > 1);

    private Integer code;
    private String desc;
    private final MyFunction function;

    public static Boolean isOverTime(Integer code, Integer count) {
        for (FunctionEnum value : FunctionEnum.values()) {
            if (Objects.equals(value.getCode(), code)) {
                return value.getFunction().proceed(count);
            }
        }
        throw new RuntimeException();
    }

    @FunctionalInterface
    public interface MyFunction {
        Boolean proceed(Integer t);
    }
}

你可能感兴趣的:(enum,java)