I've an ArrayList of objects.
ArrayList<Item> blog_titles = new ArrayList<Item>();
I want to sort the ArrayList in the descending order of one of the datamembers which is a DateTime value stored as String (timestamp in the code below).
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 is a generic interface:
public interface Item {
// TODO Auto-generated method stub
}
Now when i'm trying to sort the ArrayList like:
Collections.sort(blog_titles);
I get the following error message:
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>>
How do i fix the above error & is this the correct approach to sort the ArrayList in this case ?