我有一个对象的 ArrayList。
ArrayList<Item> blog_titles = new ArrayList<Item>();
我想按数据成员之一的降序对 ArrayList 进行排序,该数据成员是存储为 String 的 DateTime 值(下面代码中的时间戳)。
public class BlogItem implements Item, Comparable<BlogItem> {
public final String id;
public final String heading;
public final String summary;
public final String description;
public final String thumbnail;
public final String timestamp; // format:- 2013-02-05T13:18:56-06:00
public final String blog_link;
public BlogItem(String id, String heading, String summary, String description, String thumbnail, String timestamp, String blog_link) {
this.id = id;
this.heading = heading;
this.summary = summary;
this.description = description;
this.thumbnail = thumbnail;
this.timestamp = timestamp; // format:- 2013-02-05T13:18:56-06:00
this.blog_link = blog_link;
}
@Override
public int compareTo(BlogItem o) {
// TODO Auto-generated method stub
return this.timestamp.compareTo(o.timestamp);
}
}
Item 是一个通用接口:
public interface Item {
// TODO Auto-generated method stub
}
现在,当我尝试对 ArrayList 进行排序时:
Collections.sort(blog_titles);
我收到以下错误消息:
Bound mismatch: The generic method sort(List<T>) of type Collections is not applicable for the arguments (ArrayList<Item>). The inferred type Item is not a valid substitute for the bounded parameter <T extends Comparable<? super T>>
我如何解决上述错误&在这种情况下这是对 ArrayList 进行排序的正确方法吗?