In Java, the following code returns false on both queries. Why? Wouldn't it be simpler for method references to be singleton? It would certainly make attaching and detaching listeners a lot simpler. As it is you need to keep a constant for any method reference that will need to be equivalence checked, you can't just use the method reference operator at every necessary location.
public class Main {
public Main() {
// TODO Auto-generated constructor stub
}
public void doStuff() {
}
public static void main(String[] args) {
Main main = new Main();
Runnable thing1 = main::doStuff;
Runnable thing2 = main::doStuff;
System.out.println(thing1 == thing2); // false
System.out.println(thing1.equals(thing2)); // false
}
}
main
andMain.class.getMethod("doStuff")
(Thanks for the tip @CostiCiudatu) – Hepato