比较Java中的引用 [英] Comparing references in Java

查看:90
本文介绍了比较Java中的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设您已经覆盖了对象的equals()和hashCode()方法,因此他们使用对象的字段。

Let's say that you have overridden an object's equals() and hashCode() methods, so that they use the object's fields.

如何检查是否有两个引用是对同一个对象,ala the stock equals()方法?

How you do you check if two references are to the same object, ala the stock equals() method?

推荐答案

使用 == 对象进行身份比较。

Use == on objects to perform identity comparison.

这是的默认实现等于()确实如此,但通常会覆盖 equals()作为等效内容检查。

That is what the default implementation of equals() does, but one normally overrides equals() to serve as an "equivalent content" check.

这篇关于比较Java中的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆