java – 番石榴ComparisonChain列表?

我正在尝试使用ComparisonChain在类中实现compareTo()但是该类包含List而compare()不接受它们,因为List没有实现Comparable.关于如何使这项工作的任何想法?

代码子集看起来像这样:

public class User() {
  String name;
  List<String> emails;

  ...

  public int compareTo(User that) {
    return ComparisonChain().start()
                            .compare(this.name, that.name)
                            .compare(this.emails, that.emails)  // Fails on this line
                            .result();
  }
}
最佳答案
ComparisonChain.start()
    .compare(this.name, that.name)
    .compare(this.emails, that.emails,
       Ordering.<String>natural().lexicographical())
    .result();

转载注明原文:java – 番石榴ComparisonChain列表? - 代码日志