目前我正在學習Java。我有問題java.utils.Collections
,NetBeans不斷給我這個錯誤。找不到合適的方法Collections.sort(列表)
no suitable method found for sort(List<MovieSession>)
method Collections.<T#1>sort(List<T#1>) is not applicable
(inference variable T#1 has incompatible bounds
equality constraints: MovieSession
upper bounds: Comparable<? super T#1>)
method Collections.<T#2>sort(List<T#2>,Comparator<? super T#2>) is not applicable
(cannot infer type-variable(s) T#2
(actual and formal argument lists differ in length))
where T#1,T#2 are type-variables:
T#1 extends Comparable<? super T#1> declared in method <T#1>sort(List<T#1>)
T#2 extends Object declared in method <T#2>sort(List<T#2>,Comparator<? super T#2>
我有下面的類MovieSession
public class MovieSession implements Comparable<MovieSession> {
@Override
public int compareTo(MovieSession currentMovieSession) {
}
}
及主要方法
public static void main(String[] args) {
List<MovieSession> movieSessions = new ArrayList<MovieSession>();
MovieSession cinema1 = new MovieSession("XYZ", 'R', new Time(10, 10, 10));
MovieSession cinema2 = new MovieSession("ABC", 'G', new Time(11, 00, 00));
movieSessions.add(cinema1);
movieSessions.add(cinema2);
Collections.sort(movieSessions);
System.out.print(movieSessions);
}
不知道是怎麼回事錯在這裏。
爲什麼到處都使用原始類型? – user2357112
哦,等等,他們只是看起來很生硬,因爲你沒有正確的代碼格式。 – user2357112
感謝編輯它總是發生在我身邊 – WonderGal