I'm trying in my code to use the following expression
Map<String, String> headersMap =
Collections.list(request.getHeaderNames())
.stream()
.collect(Collectors.toMap(
name -> name,
request::getHeader));
as shown here but Eclipse complains of type mismatch:
What's the correct way to accomplish this and why? Why does the one in the link not uses any casting?
UPDATES:
Considering the suggestion from @Eugene, the following monstrosity seems to make the compiler happier:
Map<String, String> headersMap = new HashMap<>();
Collections.list(request.getHeaderNames())
.forEach(x -> headersMap.put((String)x, (String)request.getHeader((String)x)));
Perhaps there are more succinct ways of expressing it in Java 8?