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);
        }
    }
}

3 comments
Comment actions Permalink

Am I not posting this in the right place?

0
Comment actions Permalink

I don't see the issue on IntelliJ IDEA 13.1 EAP.

Bas

0
Comment actions Permalink

Thanks Bas. :)

0

Please sign in to leave a comment.