笔记
String中”==”和equals()的区别
//字符串中==和equals()的区别
Snot snot = new Snot();
System.out.println(snot.s1 == snot.s2);
System.out.println(snot.s1 == snot.s3);
System.out.println(snot.s3 == snot.s4);
System.out.println(snot.s1.equals(snot.s3));
System.out.println(snot.s4.equals(snot.s3));
super,this,static,final关键字
//super 调用父类的方法和属性,调用父类的构造器,必须把super放在第一行
// this指的是调用该方法的对象
// static 静态的属性用类名调用
// 静态的方法只能调用静态的属性
// final修饰class,class不能被继承;修饰方法,方法不能被重写;修饰常量,常量大写用下划线隔开(N_S)
26262882 <_<哈希码
重写equals(), toString() 方法,了解hashCode()方法
e.g.
@Override
public boolean equals(Object obj) {
if (obj != null) {
if (obj instanceof Student) {
if (((Student) obj).getId() == this.getId() ) {
boolean isSameStudent = true;
return isSameStudent;
}
}
}
return super.equals(obj);
}
………略