62,614
社区成员
发帖
与我相关
我的任务
分享
package com.Code_Person;
import java.util.*;
public class Code
{
public final int id; //身份证号已确认,不能修改
public Code(int id)
{ this.id=id; }
//这里提示我overrides java.lang.Object.equals
//问题1:为什么我随便写个名字叫做equals的方法就重载了?
public boolean equals(Object anObject)
{
//问题2:传进来的时候类型和参数不就确定了吗,为什么这里还要判断一次?
if(anObject instanceof Object)
{
//Incompatible operand types int and Code
//不兼容的操作数类型int和代码
// return this.id==(Code)anObject.id;
//问题3:要改成下面这种写法才没报错 为什么 上面不是已经做了类型转换了吗0.0?
Code tmp=(Code)anObject;
return this.id==tmp.id;
}
return false;
}
}
if(anObject instanceof Code)
return this.id==((Code)anObject).id;