Refactoring bug with lambda to method reference
I'm not sure this is where to post this but I found a bug in 12.1.6 which may exist in 13 using Java build 1.8.0-ea-b118. Can someone verify?
In the following code example the (Person p) -> p.getName() expression will show the "Can be replaced with method reference" inspection. If you chose that option you will have a compiler error on the Collectors.mapping method.
Code Below:
public class GroupBySample {
public static void main(String[] args) {
new GroupBySample();
}
public GroupBySample() {
Stream<Person> people = Stream.of(new Person("Paul", 24), new Person("Mark", 30), new Person("Will", 28));
Object peopleByAge = people.collect(Collectors.groupingBy(Person::getAge, Collectors.mapping((Person p) -> p.getName(), Collectors.toList())));
System.out.println(peopleByAge);
}
static final class Person {
private String name;
private int age;
Person(String name, int age) {
this.name = name;
this.age = age;
}
String getName() {
return name;
}
int getAge() {
return age;
}
@Override
public String toString() {
return String.format("Person{name='%s', age=%d}", name, age);
}
}
}
请先登录再写评论。
Am I not posting this in the right place?
I don't see the issue on IntelliJ IDEA 13.1 EAP.
Bas
Thanks Bas. :)