The following code does not compile:
HashSet<Integer> nlsCandidates; // added here to help read the stream coding below
EnumSet<ScConstraint>[] rowConstraints; // added here to help read the stream coding below
EnumSet<ScConstraint> tbd = nlsCandidates.stream()
.flatMap(p -> rowConstraints[10*k + p].stream())
.filter(cstr -> !s.contains(cstr.RC))
.collect(EnumSet.noneOf(ScConstraint.class), (c, cstr) -> c.add(cstr), EnumSet::addAll);
This is the error message:
no suitable method found for collect(EnumSet<ScConstraint>,(c,cstr)->[...]cstr),EnumSet::addAll)
.collect(EnumSet.noneOf(ScConstraint.class), (c, cstr) -> c.add(cstr), EnumSet::addAll);
^
method Stream.<R#1>collect(Supplier<R#1>,BiConsumer<R#1,? super ScConstraint>,BiConsumer<R#1,R#1>) is not applicable
(cannot infer type-variable(s) R#1
(argument mismatch; no instance(s) of type variable(s) E exist so that EnumSet<E> conforms to Supplier<R#1>))
method Stream.<R#2,A>collect(Collector<? super ScConstraint,A,R#2>) is not applicable
(cannot infer type-variable(s) R#2,A
(actual and formal argument lists differ in length))
where R#1,T,E,R#2,A are type-variables:
R#1 extends Object declared in method <R#1>collect(Supplier<R#1>,BiConsumer<R#1,? super T>,BiConsumer<R#1,R#1>)
T extends Object declared in interface Stream
E extends Enum<E> declared in method <E>noneOf(Class<E>)
R#2 extends Object declared in method <R#2,A>collect(Collector<? super T,A,R#2>)
A extends Object declared in method <R#2,A>collect(Collector<? super T,A,R#2>)
I need the Supplier
to return an empty EnumSet. How can I achieve that?