Java-8 stream expression to 'OR' several enum values together
I am aggregating a bunch of enum values (different from the ordinal values) in a foreach loop. int output = 0; for (TestEnum testEnum: setOfEnums) { output |= testEnum.getValue(); } Is there a way to do this in streams API? If I use a lambda like this in a Stream<TestEnum> : setOfEnums.stream().forEach(testEnum -> (output |= testEnum.getValue()); I get a compile time error that says, 'variable used in lambda should be effectively final'. Predicate represents a boolean valued function, you need to use reduce method of stream to aggregate bunch of enum values. if we consider that you have