public class Students{
private String sid;
private String sname;
private int age;
private char sex;
public String getSid() {
return sid;
}
public void setSid(String sid) {
this.sid = sid;
}
public String getSname() {
return sname;
}
public void setSname(String sname) {
this.sname = sname;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public char getSex() {
return sex;
}
public void setSex(char sex) {
this.sex = sex;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + age;
result = prime * result + sex;
result = prime * result + ((sid == null) ? 0 : sid.hashCode());
result = prime * result + ((sname == null) ? 0 : sname.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
News other = (News) obj;
if (age != other.age)
return false;
if (sex != other.sex)
return false;
if (sid == null) {
if (other.sid != null)
return false;
} else if (!sid.equals(other.sid))
return false;
if (sname == null) {
if (other.sname != null)
return false;
} else if (!sname.equals(other.sname))
return false;
return true;
}
@Override
public String toString() {
return "News [age=" + age + ", sex=" + sex + ", sid=" + sid
+ ", sname=" + sname + "]";
}
}
可以再详细一点吗?重写equals方法、hashCode方法和toString方法是什么意思
这是个javaBean吧。
private String name;
private Integer id;
private Integer age;
private String sex;
然后shift+alt+s选择generate toString()/generate hashCode and equals.../generate getters and setters...