Java Stream collect after flatMap returns List<Object> instead of List<String>
问题 I tried the following code using Java 8 streams: Arrays.asList("A", "B").stream() .flatMap(s -> Arrays.asList("X", "Y").stream().map(s1 -> s + s1)).collect(Collectors.toList()); What I get is a List<Object> while I would expect a List<String> . If I remove the collect and I try: Arrays.asList("A", "B").stream().flatMap(s -> Arrays.asList("X", "Y").stream().map(s1 -> s + s1)); I correctly get a Stream<String> . Where am I wrong? Can someone help me? Many thanks in advance. Edit: The problem is