当前位置:网站首页>Equals method
Equals method
2022-07-07 20:00:00 【Whiteye too white】
“==” And equals The difference between
“==” For basic types , Compare values ; For reference types, the address is compared .
Object Class equals The default implementation of is equivalent to “==”, That is, compare the addresses of reference types .
Java There are many classes in the library ( Such as String、Date、Long、HashMap and File Class etc. ) It's all rewritten Object Class equals Method , Lead to its and “==” Unequivalence .
String Overridden in class equals First “==” Compare the reference addresses of two reference types , Same returns true, Compare the strings with different reference addresses .
rewrite equals Method must override hashCode Method
hashCode One of the things that methods actually have to do is , For the sake of equals Method returns the same hash value for the same object .
Object Class equals Method to distinguish two objects by comparing the address value , That is to use “==”. And if we rewrite it according to business needs equals Method implementation , Then it should also be rewritten at the same time hashCode Method implementation . otherwise hashCode Method still returns the basis Object Class based on address value integer Hash value .
边栏推荐
- Throughput
- CSDN语法说明
- el-upload上传组件的动态添加;el-upload动态上传文件;el-upload区分文件是哪个组件上传的。
- 2022如何评估与选择低代码开发平台?
- vulnhub之Funfox2
- Interpretation of transpose convolution theory (input-output size analysis)
- torch. nn. functional. Pad (input, pad, mode= 'constant', value=none) record
- 9 原子操作类之18罗汉增强
- Sword finger offer II 013 Sum of two-dimensional submatrix
- LC:字符串转换整数 (atoi) + 外观数列 + 最长公共前缀
猜你喜欢
随机推荐
[RT thread env tool installation]
R语言ggplot2可视化:使用ggpubr包的ggdensity函数可视化分组密度图、使用stat_overlay_normal_density函数为每个分组的密度图叠加正太分布曲线
841. String hash
Kubernetes——kubectl命令行工具用法详解
开源重器!九章云极DataCanvas公司YLearn因果学习开源项目即将发布!
R语言ggplot2可视化:使用ggpubr包的ggstripchart函数可视化分组点状条带图(dot strip plot)、设置position参数配置不同分组数据点的分离程度
R语言使用ggplot2函数可视化需要构建泊松回归模型的计数目标变量的直方图分布并分析构建泊松回归模型的可行性
ASP.NET体育馆综合会员管理系统源码,免费分享
torch.nn.functional.pad(input, pad, mode=‘constant‘, value=None)记录
Redis master-slave and sentinel master-slave switchover are built step by step
剑指 Offer II 013. 二维子矩阵的和
Visual Studio 插件之CodeMaid自动整理代码
IP 工具类
8 CAS
Detailed explanation of Flink parallelism and slot
Kunpeng developer summit 2022 | Kirin Xin'an and Kunpeng jointly build a new ecosystem of computing industry
微信公众号OAuth2.0授权登录并显示用户信息
what‘s the meaning of inference
位运算介绍
LeetCode力扣(剑指offer 36-39)36. 二叉搜索树与双向链表37. 序列化二叉树38. 字符串的排列39. 数组中出现次数超过一半的数字