我正在尝试对数组进行排序,但由于某种原因,我的 compareTo 函数中出现以下错误:
Cannot invoke compareTo(int) on the primitive type int
我的代码:
private void sortFriendList()
{
Arrays.sort(friendsList, new Comparator<FacebookUser>() {
@Override
public int compare(FacebookUser lhs, FacebookUser rhs) {
ChatMessage[] firstChatMessages = app.getDatabaseManager().getChatMessages(lhs.getId());
ChatMessage[] lastChatMessages = app.getDatabaseManager().getChatMessages(rhs.getId());
int firstLastMessageTime = (int) firstChatMessages[firstChatMessages.length-1].getTime();
int lastLastMessageTime = (int) lastChatMessages[firstChatMessages.length-1].getTime();
return firstLastMessageTime.compareTo(lastLastMessageTime);
}
});
}
应该对存储在 long 类型中的数组购买时间进行排序的代码(我已将其转换为 int)