当前位置:网站首页>==What is the difference between and equals?
==What is the difference between and equals?
2022-06-24 00:01:00 【The fifth brother of the Wang family】
==: Operator , Used to compare base type variables with reference type variables .
For base type variables , Whether the compared variables hold the same values , The type does not have to be the same .
short s1 = 1; long l1 = 1;
// result :true. Different types , But the value is the same
System.out.println(s1 == l1);For reference type variables , The comparison is whether the addresses of the two objects are the same .
Integer i1 = new Integer(1);
Integer i2 = new Integer(1);
// result :false. adopt new establish , Point to two different objects in memory
System.out.println(i1 == i2);equals:Object Methods defined in class , It is usually used to compare whether the values of two objects are equal .
equals stay Object The method is actually equivalent to ==, But in actual use ,equals It is usually overridden to compare whether the values of two objects are the same .
Integer i1 = new Integer(1);
Integer i2 = new Integer(1);
// result :true. Two different objects , But with the same value
System.out.println(i1.equals(i2));
// Integer Of equals Rewriting methods
public boolean equals(Object obj) {
if (obj instanceof Integer) {
// Are the values saved in the comparison object the same
return value == ((Integer)obj).intValue();
}
return false;
}two-object hashCode() identical , be equals() It must be for true, Am I right? ?
incorrect .hashCode() and equals() The relationship is as follows :
When there is a.equals(b) == true when , be a.hashCode() == b.hashCode() It must be true ,
In turn, , When a.hashCode() == b.hashCode() when ,a.equals(b) Not necessarily for true.
边栏推荐
- Leetcode——链表笔试题
- Three cool and coquettish bottom navigation
- 2.摄像机标定
- What is medical treatment? AI medical concept analysis AI
- fatal: The upstream branch of your current branch does not match the name of your current branch.
- 合成大西瓜小游戏微信小程序源码/微信游戏小程序源码
- 工作中一些常用的工具函数
- [technical grass planting] Tencent Yunhao wool (consumption) record on the double 11
- Gbase observation: extended analytical database
- Server2022 activation
猜你喜欢

EF Core中的三类事务(SaveChanges、DbContextTransaction、TransactionScope)

Inftnews | where should the future of the creator economy go in the Web3 world?

Digital property management has become a trend. How can traditional property companies achieve digital butterfly change through transformation?

Recommend 4 flutter heavy open source projects

跟着CTF-wiki学pwn——ret2text

图扑软件智慧风电:数字孪生 3D 风机智能设备运维

6月25日PMP考试敏捷怎么考?替你分忧解难

解决项目依赖报红问题

物联网卡设备接入EasyCVR,如何查看拉流IP以及拉流时间?

格林公式挖洞法中内曲线顺时针的直观解释
随机推荐
重载(Overload)和重写(Override)的区别?
Dot and cross product
开口式霍尔电流传感器助力直流配电改造
UART协议时序总结
C语言c89(c90)的所有的32个关键字分类
逆向工具IDA、GDB使用
How to use data warehouse to create time series
MySQL architecture (basic)
Three types of transactions in EF core (saveChanges, dbcontexttransaction, transactionscope)
数字物业管理成趋势,传统物业公司如何通过转型实现数字化蝶变?
log Network Execution Time
老龄化下背景下,综合能效管理平台为医院保驾护航
1. < tag dynamic programming and path combination problem > lt.62 Different paths + lt.63 Different paths II
GBASE观察:扩展分析型数据库
extern、struct等关键字
Notepad++实用功能分享(正则行尾行首替换常用方法、文本比对功能等)
Docker deploy redis
Kubernetes basic concept
fatal: The upstream branch of your current branch does not match the name of your current branch.
【Bug】C# IQueryable里的元素更改不了值