@Override public int hashCode() { // TODO Auto-generated method stub return this.getId()+this.getName().hashCode(); } @Override public boolean equals(Object obj) { // TODO Auto-generated method stub if(this==obj) { return true; } if(obj instanceof Items) { Items i = (Items)obj; if(this.getId()==i.getId()&&this.getName().equals(i.getName())) { return true; } else { return false; } } else { return false; } }
Java 中的instanceof 运算符是用来在运行时指出对象是否是特定类的一个实例。instanceof通过返回一个布尔值来指出,这个对象是否是这个特定类或者是它的子类的一个实例。
转载于:https://www.cnblogs.com/xuedexin/articles/5625519.html
