在Java中,以下代码在两个查询上都返回false.为什么?方法引用是单例是不是更简单?它肯定会使听众的连接和分离变得更加简单.因为您需要为需要进行等效性检查的任何方法引用保持常量,所以不能在每个必要位置使用方法引用运算符.
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
}
}
Run Code Online (Sandbox Code Playgroud)