类 排序 定义比较

public class StationSongBean implements Comparable<StationSongBean>{
    private int song_id;
    private String song_name;
    private String singer_name;
    private String user_nickname;
    private boolean is_support;  //是否已支持过
    private int amount_support;

    //取值函数
    public void setSong_id(int song_id) {
        this.song_id = song_id;
    }
    public String getUser_nickname() {
        return user_nickname;
    }
    public String getSongName() {
        return song_name;
    }
    public String getSingerName() {
        return singer_name;
    }
    public int getAmount_support() {
        return amount_support;
    }
    public boolean getIs_support() {
        return is_support;
    }

    //赋值函数
    public int getSong_id() {
        return song_id;
    }
    public void setUser_nickname(String user_nickname) {
        this.user_nickname = user_nickname;
    }
    public void setSongName(String song_name) {
        this.song_name = song_name;
    }
    public void setSingerName(String singer_name) {
        this.singer_name = singer_name;
    }
    public void setAmount_support(int amount_support) {
        this.amount_support = amount_support;
    }
    public void setIs_support(boolean is_support) {
        this.is_support = is_support;
    }

    @Override
    public int compareTo(@NonNull StationSongBean stationSongBean) {
        return stationSongBean.getAmount_support()-this.amount_support;
    }
}
原文地址:https://www.cnblogs.com/zhaozilongcjiajia/p/11692223.html