Can you collect(joining()) without mapping to string?

前端 未结 1 1994
温柔的废话
温柔的废话 2021-01-15 08:55

I am reading java 8 in action, and the author says that if you have a class that overrides the toString method, you don\'t need to map the stream to Strings when doing colle

1条回答
  •  别那么骄傲
    2021-01-15 09:32

    Whatever the book says is wrong and your interpretation is right (unless the point is entirely different and you did not get it)

    people.stream()
    

    will generate a Stream, while Collectors.joining has a definition of:

    public static Collector joining()
    

    obviously this can't work as Person is not an instance of CharSequence.

    0 讨论(0)
提交回复
热议问题