目前我正在学习Java。
我遇到java.utils.Collections
问题,NetBeans继续给我这个错误。
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);
}
不确定这里出了什么问题。
答案 0 :(得分:0)
我复制了您的代码,添加了缺失的位,并且运行时没有任何错误
主:
RewriteEngine On
RewriteBase /manual/
RewriteCond %{REQUEST_FILENAME} !-f # Existing File
RewriteCond %{REQUEST_FILENAME} !-d # Existing Directory
RewriteRule . /manual/index.php? [L]
RewriteRule ^([^/]*)\/$ type=post&post=$1 [L]
MovieSession:
import java.sql.Time;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class TestBed {
public static void main(String[] args) {
List<MovieSession> movieSessions = new ArrayList<MovieSession>();
MovieSession session1 = new MovieSession("Logan", 'R', new Time(10, 10, 10));
MovieSession session2 = new MovieSession("Baby Boss", 'G', new Time(11, 00, 00));
MovieSession session3 = new MovieSession("Guardians Of The Galaxy ", 'M', new Time(9, 30, 00));
MovieSession session4 = new MovieSession("Moana", 'G', new Time(13, 45, 00));
movieSessions.add(session1);
movieSessions.add(session2);
movieSessions.add(session3);
movieSessions.add(session4);
Collections.sort(movieSessions);
System.out.println(movieSessions);
}
}
输出: [银河护卫 - M - 09:30:00,洛根 - R - 10:10:10,宝贝老板 - G - 11:00:00,摩纳 - G - 13:45:00]