彩笔笔记2016/12/5——改写equals
来源:互联网 发布:华通云数据与马云关系 编辑:程序博客网 时间:2024/06/10 03:21
package Object;
public class Graph{
int edge;
int area;
int girth;
public int getEdge() {
return edge;
}
public void setEdge(int edge) {
this.edge = edge;
}
public int getArea() {
return area;
}
public void setArea(int area) {
this.area = area;
}
public int getGirth() {
return girth;
}
public void setGirth(int girth) {
this.girth = girth;
}
@Override
public boolean equals(Object obj) { //改写equals
// TODO Auto-generated method stub
if(this==obj){
return true;
}if(obj instanceof Graph){
if(this.edge==edge){
return true;
}else if(this.girth==girth){
return true;
}else if(this.area==area){
return true;
}
}
return false;
}
public static void main(String[]args){
Graph g1=new Graph();
g1.setEdge(4);
g1.setGirth(16);
g1.setArea(16);
Graph g2 = new Graph();
g2.setEdge(3);
g2.setGirth(16);
g2.setArea(16);
System.out.println(g1.equals(g2));
}
}
int edge;
int area;
int girth;
public int getEdge() {
return edge;
}
public void setEdge(int edge) {
this.edge = edge;
}
public int getArea() {
return area;
}
public void setArea(int area) {
this.area = area;
}
public int getGirth() {
return girth;
}
public void setGirth(int girth) {
this.girth = girth;
}
@Override
public boolean equals(Object obj) { //改写equals
// TODO Auto-generated method stub
if(this==obj){
return true;
}if(obj instanceof Graph){
if(this.edge==edge){
return true;
}else if(this.girth==girth){
return true;
}else if(this.area==area){
return true;
}
}
return false;
}
public static void main(String[]args){
Graph g1=new Graph();
g1.setEdge(4);
g1.setGirth(16);
g1.setArea(16);
Graph g2 = new Graph();
g2.setEdge(3);
g2.setGirth(16);
g2.setArea(16);
System.out.println(g1.equals(g2));
}
}
0 0
- 彩笔笔记2016/12/5——改写equals
- 彩笔笔记2016/12/1——多态
- 彩笔笔记2016/12/2——内部类
- 彩笔笔记2016/12/6——collection
- 彩笔笔记2016/12/7——map
- 彩笔笔记2016/12/8——filewriter ,filereader
- 彩笔笔记2016/11/22——rpm与yum安装程序
- 彩笔笔记2016/11/23——创建用户与配置挂载新硬盘
- 彩笔笔记2016/11/24——权限操作与scp、sftp命令
- 彩笔笔记2016/11/25——jdk的环境变量设置
- 彩笔笔记2016/11/28——java、jar基本命令与i++与基础运算
- 彩笔笔记2016/11/29——break、栈堆内存
- 彩笔笔记2016/11/30——构造器、调用方法与类
- Effective Java——Item8:改写equals的时候总是要改写hashCode
- 2019——证明自己是个大彩笔
- Effective Java笔记之改写equals的通用约定
- 改写equals时总是要改写hashCode
- Java-改写equals 必须改写hashChode()
- IOS端静态代码无Bug?只需4步!
- 【玩转SQLite系列】(六)SQLite数据库应用案例实现历史搜索记录
- 微信小程序学习笔记(3)--------框架之配置
- Andorid源码下载
- 使用Artifactory搭建本地maven仓库
- 彩笔笔记2016/12/5——改写equals
- 【玩转SQLite系列】(七)打造轻量级ORM工具类SQLiteDbUtil操作数据库
- 浅谈 Scala 中下划线的用途
- RabbitMQ第一个案例:hello world
- Appium环境配置-1
- Fragment的基本应用
- js判断是否是Json对象
- springMVC接收表单传来的file,并上传
- tab栏切换案例