目前我正在学习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