在Java中使用Collection.sort时,当其中一个内部对象为null时,我应该返回什么
例:
Collections.sort(list, new Comparator<MyBean>() {
public int compare(MyBean o1, MyBean o2) {
return o2.getDate().compareTo(o1.getDate());
}
});
Run Code Online (Sandbox Code Playgroud)
让我们说o2不是null而是o2.getDate()它是,所以我应该在添加空验证时返回1或-1或0吗?