Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I'm building a query param called "id", it's a list so I have something like localhost:8080/application?id=1&id=2&id=3&id=4
(I know my method isn't enough and I need write the first
?id=
)
Method
public Map<Long, String> getSkus(List<ItemPedido> itensPedido) {
Map<Long, String> skus = new HashMap<>();
String ids = itensPedido.stream()
.filter(i -> i.getProduto() != null)
.map(i -> i.getProduto().getId())
.collect(Collectors.joining("&id="));
//TODO
return skus;
My question is: Why I received this error in Collectors.joining("&id=")?
no suitable method found for collect(java.util.stream.Collector<java.lang.CharSequence,capture#1 of ?,java.lang.String>)
[ERROR] method java.util.stream.Stream.<R>collect(java.util.function.Supplier<R>,java.util.function.BiConsumer<R,? super java.lang.Long>,java.util.function.BiConsumer<R,R>) is not applicable
[ERROR] (cannot infer type-variable(s) R
[ERROR] (actual and formal argument lists differ in length))
[ERROR] method java.util.stream.Stream.<R,A>collect(java.util.stream.Collector<? super java.lang.Long,A,R>) is not applicable
[ERROR] (cannot infer type-variable(s) R,A
[ERROR] (argument mismatch; java.util.stream.Collector<java.lang.CharSequence,capture#1 of ?,java.lang.String> cannot be converted to java.util.stream.Collector<? super java.lang.Long,A,R>))
I'm using OpenJDK
$ java -version
openjdk version "1.8.0_151"
OpenJDK Runtime Environment (build 1.8.0_151-b12)
OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.