About Question enthuware.ocpjp.v8.2.1802 :
Posted: Tue May 16, 2017 9:55 pm
Please, explain why option 1 is wrong. I can see that options 2 and 3 have wrong syntax, and option 4 is obviously correct, but what would be the "official" reason for option 1 being wrong?
When I tried to compile the code with option 1 I got
When I tried to compile the code with option 1 I got
Which I don't quite understand.Student.java:26: error: incompatible types: inference variable T#1 has incompatible bounds
Map<Integer, List<Student>> grouping = ls.stream().collect( Collectors.groupingBy(Student::getMarks,Collectors.mapping(Student::getName, Collectors.toList())) );
^
equality constraints: Student
lower bounds: String,U
where T#1,U,T#2,A,R are type-variables:
T#1 extends Object declared in method <T#1>toList()
U extends Object declared in method <T#2,U,A,R>mapping(Function<? super T#2,? extends U>,Collector<? super U,A,R>)
T#2 extends Object declared in method <T#2,U,A,R>mapping(Function<? super T#2,? extends U>,Collector<? super U,A,R>)
A extends Object declared in method <T#2,U,A,R>mapping(Function<? super T#2,? extends U>,Collector<? super U,A,R>)
R extends Object declared in method <T#2,U,A,R>mapping(Function<? super T#2,? extends U>,Collector<? super U,A,R>)
1 error