Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

finish #210

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/main/java/com/github/hcsp/polymorphism/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
import java.util.TreeSet;

public class User implements Comparable<User> {
/** 用户ID,数据库主键,全局唯一 */
/**
* 用户ID,数据库主键,全局唯一
*/
private final Integer id;

/** 用户名 */
/**
* 用户名
*/
private final String name;

public User(Integer id, String name) {
Expand Down Expand Up @@ -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) {
Expand Down