博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
重写equals()和hashCode()方法
阅读量:3970 次
发布时间:2019-05-24

本文共 632 字,大约阅读时间需要 2 分钟。

文章目录

User.java中重写equals、hashCode方法

equals()

public boolean equals(Object other) {
if (this == other) return true; if (!(other instanceof User)) return false; final User u = (User)other; if (! name.equals(u.getName())) return false; if (!birthday.equals(u.getBirthday())) return false; if (!(age==u.age)) return false; if(! gender.equals(u.gender)) return false; return true; }

hashCode()

public int hashCode() {
int result; result = name.hashCode(); result = 29 * result + getBirthday().hashCode(); return result; }

转载地址:http://vstki.baihongyu.com/

你可能感兴趣的文章
Linux SWAP分区占用率高,刷新SWAP分区方法
查看>>
Redis在新浪微博中的应用
查看>>
微博CacheService架构浅析
查看>>
Google字体库引起的首页加载缓慢的解决方法
查看>>
apache调优
查看>>
linux中rpm常用命令
查看>>
tcp连接的11种状态
查看>>
url转码和解码
查看>>
编译安装ruby1.9.3(No rvm)
查看>>
详解如何在ubuntu上安装node.js
查看>>
tmpfs用法
查看>>
你真的会python嘛?
查看>>
Python的魔法(一): 基本知识
查看>>
Python的魔法二:开发的'坑'
查看>>
mysql查询重复记录的方法
查看>>
python单元测试unittest
查看>>
Python单元测试框架
查看>>
Python自动单元测试框架
查看>>
linux curl命令详解,以及实例
查看>>
python模拟浏览器登录
查看>>