class.equals

public boolean equals(Object obj) 
1.自身和自身应该是equals的. X.equals(x) return ture
2.如果A等于B, 那么B也就等于A . X.equals(y) 那么 Y.equals(X)
3.传递性: X.equals(Y) Y.equals(Z) 那么 X.equals(Z).
4.永恒性. 始终是相等的. 今天是相等的那么明天也会是相等的.
5.对于任何的non-null数值和null值进行比较得到的结果永远是false. X.equals(null) 输出false.\


默认实现:当且仅当X.Y都指向同一个对象时.编译器才返回ture.
The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x and y,
this method returns true if and only if x and y refer to the same object (x == y has the value true).

从上文知: x = y; 和 x.equals(y);是一样的意思

equals的东西需要自己去改写. 通过复制粘贴改写equals.

instanceof:(运算符)二进制操作符 它的作用是判断其左边对象是否为其右边类的实例,返回boolean类型的数据。

Cat C = (cat)obj; 将obj强制转换成cat类型.

J2SDK提供的一些类.如string.Date等重写了equals方法.String本身对equals进行了重写. 只要字符序列一样就会输出true.

转载于:https://www.cnblogs.com/dwj-ngu/p/6143289.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值