I am trying to convert a list of patterns (whose type is string
) into predicates and for some reasons my brain keeps ending up with something close to the following code:
List<Predicate> predicates = patterns.stream()
.map(Pattern::asPredicate)
.collect(Collectors.toList());
which obviously doesn't compile. What's the best way of writing the conversion stream?
This is the error message I am getting:
Provider.java:32: error: method map in interface Stream<T> cannot be applied to given types;
.map(Pattern::asPredicate)
^
required: Function<? super String,? extends R>
found: Pattern::a[...]icate
reason: cannot infer type-variable(s) R
(argument mismatch; invalid method reference
method asPredicate in class Pattern cannot be applied to given types
required: no arguments
found: String
reason: actual and formal argument lists differ in length)
where R,T are type-variables:
R extends Object declared in method <R>map(Function<? super T,? extends R>)
T extends Object declared in interface Stream
MsisdnPartitioningProvider.java:32: error: invalid method reference
.map(Pattern::asPredicate)
^
non-static method asPredicate() cannot be referenced from a static context
Note: MsisdnPartitioningProvider.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
2 errors