diff --git a/src/main/java/com/github/hcsp/polymorphism/User.java b/src/main/java/com/github/hcsp/polymorphism/User.java index 7a601df..d52982c 100644 --- a/src/main/java/com/github/hcsp/polymorphism/User.java +++ b/src/main/java/com/github/hcsp/polymorphism/User.java @@ -6,10 +6,14 @@ import java.util.TreeSet; public class User implements Comparable { - /** 用户ID,数据库主键,全局唯一 */ + /** + * 用户ID,数据库主键,全局唯一 + */ private final Integer id; - /** 用户名 */ + /** + * 用户名 + */ private final String name; public User(Integer id, String name) { @@ -44,10 +48,16 @@ public int hashCode() { return id != null ? id.hashCode() : 0; } - /** 老板说让我按照用户名排序 */ + /** + * 老板说让我按照用户名排序 + */ @Override public int compareTo(User o) { - return name.compareTo(o.name); + if (name.compareTo(o.name) == 0) { + return id.compareTo(o.id); + } else { + return name.compareTo(o.name); + } } public static void main(String[] args) {