From 6aade77157fab9cdfea2789a91275a8bc4ed91b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cidpeng=E2=80=9D?= <630606938@qq.com> Date: Mon, 30 Aug 2021 22:06:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=85=B6=E4=B8=AD=E7=9A=84bu?= =?UTF-8?q?g?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/github/hcsp/polymorphism/User.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/github/hcsp/polymorphism/User.java b/src/main/java/com/github/hcsp/polymorphism/User.java index 7a601df..aea9744 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,9 +48,14 @@ public int hashCode() { return id != null ? id.hashCode() : 0; } - /** 老板说让我按照用户名排序 */ + /** + * 老板说让我按照用户名排序 + */ @Override public int compareTo(User o) { + if (name.compareTo(o.name) == 0) { + return id.compareTo(o.id); + } return name.compareTo(o.name); }