public static <E extends Enum<E>> boolean validateEnum(Class<E> clazz, String s) {
return EnumSet.allOf(clazz).stream().anyMatch(e -> e.name().equals(s));
}
Following is an example invocation of the above method
boolean isValid = validateEnum(Animal.class, "DOG");
boolean isValid = validateEnum(Color.class, "Red");
Can this same functionality be implemented using a Java 8 FunctionalInterface
. I have tried creating a BiPredicate
but am getting compiler errors when I try this.
final BiPredicate<String,Class> biPre = (string1, clazz) -> EnumSet.allOf(clazz).stream().anyMatch(e -> e.name().equals(s));
final BiPredicate<String,Class> biPre
tofinal BiPredicate<String,Class<Animal>> biPre
?