Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法检测Java中的两个对象是否相互别名?在 CI 猜测中,我们可以检查两个指针指向的内存地址。但是有没有办法在 Java 中做到这一点?
在java中,变量是引用,因此您可以比较它们==以查看它们是否引用同一个对象。
==
Object a = ... Object b = a; boolean areSame = (a == b); //Will be true.
if (obj1 == obj2) { // both refrences are pointing to same object }