添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
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)
                What type is getId() from getProduto() (from ItemPedido)? I'm going to guess not a String.
– Elliott Frisch
                May 7, 2018 at 20:30
                @ElliottFrisch technically speaking, any type of CharSequence would suffice not just String.
– Ousmane D.
                May 7, 2018 at 20:36
        

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.