2.1.21可比较的交易。用我们的Date类(请见2.1.1.4节)作为模板扩展你的Transaction类(请见练习1.2.13),实现Comparable接口,使交易能够按照金额排序。
解答:
public class Transaction implements Comparable<Transaction>
{
private final double amount;
public int compareTo(Transaction that)
{
if (this.amount>that.amount) return +1;
if (this.amount<that.amount) return -1;
return 0;
}
...
}
转载于:https://www.cnblogs.com/longjin2018/p/9860043.html