Why I cannot invoke stream() on the array type Enum?
DummyEnum[] array = DummyEnum.values();
array.stream(); // Compile Error
ENUM:
public enum DummyEnum {
Hello("Hello"), Welcome("Welcome");
private String greeting;
private DummyEnum(final String greeting) {
this.greeting = greeting;
}
public String getValue() {
return greeting;
}
}
DummyEnum.values()creates a new array on each call. That's usually not a problem, but if you're doing it in extremely hot code you might want to cache a single instance in a static field instead.