我对 Vehicle other = (Vehicle)obj;
的作用感到困惑。它是否创建一个变量 other
并将 obj
复制到其中?
@Override
public boolean equals (Object obj) {
if (this == obj) return true;
if (!(obj instanceof Vehicle)) return false;
Vehicle other = (Vehicle)obj;
return ( type.equals(other.type)
&& size == other.size
&& uitstoot == other.uitstoot
);
}
最佳答案
首先检查obj
是否是Vehicle
的实例
if (!(obj instanceof Vehicle)) 返回 false;
如果是,则将其转换为 Vehicle
类 - 即从该点开始,它将被解释为 Vehicle
实例
Vehicle other = (Vehicle)obj;
关于java - Vehicle other = (Vehicle)obj; 是什么意思?做?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21219389/