建议四十一:让多重继承成为现实
interface Father {
public int strong();
}
interface Mother {
public int kind();
}
class FatherImpl implements Father {
@Override
public int strong() {
return 8;
}
}
class MotherImpl implements Mother {
@Override
public int kind() {
return 8;
}
}
class son extends FatherImpl implements Mother {
@Override
public int strong() {
return super.strong() + 1;
}
@Override
public int kind() {
return new MotherSpecial().kind();
}
private class MotherSpecial extends MotherImpl {
@Override
public int kind() {
return super.kind() - 1;
}
}
}
通过使用内部类实现多重继承
建议四十二:让工具类不可实例化
建议四十三:避免对象的浅拷贝
浅拷贝只是java提供的一种简单的拷贝机制,不便于直接使用。
建议四十四:推荐使用序列化实现对象的拷贝
建议四十五:覆写equals方法时不要识别不出自己
建议四十六:equals应该考虑null值场景
建议四十七:在equals中使用getClass进行类型判断
obj!=null&&obj.getClass() == this.getClass()
建议四十八:覆写equals方法必须覆写hashCode方法
建议四十九:推荐覆写toString方法
建议五十:使用package-info类为包服务
package-info不能随便创建,主要用于开发包