equals and hashCode

Robert J. Saulnier robert.j.saulnier at gmail.com
Fri Oct 26 12:11:58 PDT 2012

Any plans on having lambdas override equals and hashCode?

I wanted to use a lambda as a key in a Map, but if you get the key
from different classes, they are not equal.

class A {

    void m() {
        Container.find(this::m); // <------ this::m should be equal to...

class B {

    public static void main(String[] args) {
        A a = new A();

        Container.find(a::m); // <-------- ...a::m.

class Container {

    public static Object find(Runnable r) {
        //find something

Right now, the compiler will generate an inner class of A for this::m
and an inner class of B for a::m. I think there might be use cases
where these two inner classes are equal with matching hashCodes.

- Bob

More information about the lambda-dev mailing list