实现Comparable接口可以使用java.util.Collections.sort对集合排序,也可以使用对象1.compareTo(对象2)进行排序;
使用java.util.Collections.sort对集合排序时可以自定义Comparator;
package com.company;
/**
* Title:
*
* @Author
* @CreateTime 2019/6/6 18:34
*/
public class Product implements Comparable<Product> {//实现Comparable接口
private Double price;
private Integer sales;
public Product(Double price, Integer sales) {
this.price = price;
this.sales = sales;
}
public Double getGMV() {
return price * sales;
}
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
public Integer getSales() {
retur