我正在尝试通过媒体标题对媒体的数组列表(实现为Movie类和Album类的接口)进行排序。
以下是Album类的一些代码,与movie类的几乎相同
public class Album implements Media, Comparable<Media> {
public Album(String title, int copies, String artist, String songs) {
this.title = title;
this.copies = copies;
this.artist = artist;
this.songs = songs;
}
public String getTitle() {
return this.title;
}
public int getCopies() {
return this.copies;
}
public String getArtist() {
return this.artist;
}
public String getSongs() {
return this.songs;
}
public String getRating() {
return null;
}
public int compareTo(Media media) {
int answer = 0;
if (this.title.compareTo(media.getTitle()) > 0) {
answer = 1;
} else if (this.title.compareTo(media.getTitle()) < 0) {
answer = -1;
} else if (this.title.compareTo(media.getTitle()) == 0) {
answer = 0;
}
return answer;
}
}
但是,当我尝试使用
Collections.sort(media);
它给我一个错误“类型集合中的方法sort(List )不适用于参数(ArrayList )”
有人知道如何清除错误吗?
Update your Comparable declaration to use any subclass that extends
Media