当前位置:网站首页>14 object class = = and equals
14 object class = = and equals
2022-07-21 13:02:00 【Where is the shepherd boy】
be-all java object ( Including arrays ) All of them Object Attributes of a class And methods
toString(); yes Object Attributes of a class And methods However, he is usually rewritten public String toString(){}
Method rewriting override
1 Usually, subclasses override parent methods Rewrite directly to overwrite ( name Same formal parameters )
2. return type And declare exception types Subclass less than or equal to parent class The parent class returns the parent class of another class Subclasses can also Go back to this You can also return subclasses of this parent class But you cannot return a class larger than the parent class of this class
“==” Whether the representatives are the same If the basic type Then it means that the values are equal If it's a reference type said The address is equal The same object
equal yes Object A method is provided Define whether the object contents are equal Usually rewrite to judge
for instance In the public security system If the ID card is the same Auto same
Right click stand alone directly source add to equals Special comparison Let's judge by a certain item
if (this == obj) // If The addresses passed are equal Go straight back to true
return true;
if (obj == null)// If empty It's a mistake
return false;
if (getClass() != obj.getClass()) // If the types are different be false
return false;
User other = (User) obj; // Forced transformation Compare
if (id != other.id)
return false;
return true;
You can also write by yourself But pay attention to the return parameters
public boolean equals(User obj) {
if(this.id==obj.id) return true;
return false;
}
Use default equals and == When judging an array Because arrays belong to objects So the return value must be false Because the comparison is the address
边栏推荐
- one million one hundred and eleven thousand one hundred and eleven
- Chen Hehong: Construction and application of alime mkg, a multimodal knowledge map of Alibaba new retail
- shell基础之逻辑控制
- 2018MySQL技术问答集锦,希望能给喜欢MySQL的同学一些帮助
- 处理imagenet2012数据集
- 使用公网IP自建数据库这种DTS实例类型需要注意哪些点?
- DTS中的数据库账号出现问题最多的是哪几种账号?
- 000
- SVN小乌龟 merge分支到主干时,代码冲突的解决思路
- Pr 2022 22.5中文版
猜你喜欢
2022清华暑校笔记之L2_1神经网络的基本组成
字符串匹配(华为)
综述 | 实例分割研究
[translation] in depth understanding of modern web browsers (4)
AI如何做新冠疫情预测?佐治亚理工最新《以数据为中心的流行病预测》综述
The 22 pictures show you in-depth analysis of prefix, infix, suffix expressions and expression evaluation
In that year, the story behind the opening of wild cattle in the Spring Festival Gala
二分查找
用Calendar中的add()方法对时间加减,获取时间范围,读取动态数据字典。
How does AI predict the COVID-19? A summary of Georgia Institute of technology's latest "data centric epidemic prediction"
随机推荐
【图像处理】Pyefd.elliptic_fourier_descriptors的使用方式
Leetcode exercise - Sword finger offer 66 Build product array
正则表达式获取两个标识中间的内容
In that year, the story behind the opening of wild cattle in the Spring Festival Gala
What is the difference between self built database transmission through dedicated line /vpn gateway / intelligent access gateway?
14 Object类 == 和equals
【Matplotlib 画图】
陈河宏:阿里新零售多模态知识图谱AliMe MKG的建设与应用
Develop a remote control software using easy language
DTS中的数据库账号出现问题最多的是哪几种账号?
P2404 自然数的拆分问题
选择ECS上的自建数据库这种接入方式,有哪些需要注意的事项?
What is public IP self built database?
Sqlserver BCP参数解释和字符格式选择和故障处理小结
预制财务凭证BAPI
Chapter 9 Yunji datacanvas ylearn causal learning open source project: from prediction to decision making
什么是DTS中的数据库账号?
国密curl的用法指南
Exercice leetcode - Échange de doigts 66. Construire un tableau de produits
AI如何做新冠疫情预测?佐治亚理工最新《以数据为中心的流行病预测》综述