我有这个对象:
COSTOS Costos = new COSTOS(1781, 359.13, "BISAG.SUP.PUER.TRA.I", "67550T9AT00ZZ");
COSTOS Herramienta = new COSTOS(1795, 299.11, "BISAG.INF.PUER.TRA.I", "67960T2MT02ZZ");
这是我的课:
public class COSTOS implements Comparable<COSTOS>{
public int referencia;
public double monto;
public String descripcion;
public String NumeroParte;
//Constructor
//getters setters
另外,我实现了 HashCode 并等于:
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((NumeroParte == null) ? 0 : NumeroParte.hashCode());
result = prime * result + ((descripcion == null) ? 0 : descripcion.hashCode());
long temp;
temp = Double.doubleToLongBits(monto);
result = prime * result + (int) (temp ^ (temp >>> 32));
result = prime * result + referencia;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
COSTOS other = (COSTOS) obj;
if (NumeroParte == null) {
if (other.NumeroParte != null)
return false;
} else if (!NumeroParte.equals(other.NumeroParte))
return false;
if (descripcion == null) {
if (other.descripcion != null)
return false;
} else if (!descripcion.equals(other.descripcion))
return false;
if (Double.doubleToLongBits(monto) != Double.doubleToLongBits(other.monto))
return false;
if (referencia != other.referencia)
return false;
return true;
}
我如何实现一种可以打印所有不等于的属性的方法?
我尝试使用“import java.util.Objects;” 使用:“Objects.hash(referencia, monto, descripcion, NumeroParte);”,这样可以给我打印的结果
一只萌萌小番薯
森栏
芜湖不芜
随时随地看视频慕课网APP
相关分类