我嘗試獲得從流的列表,但我有一個例外。java的:不兼容的類型:推斷變量T具有不相容界限等式約束:下界:java.util.List的<>
這裏是一個對象的列表影片對象。
public class Movie {
private String example;
private List<MovieTrans> movieTranses;
public Movie(String example, List<MovieTrans> movieTranses){
this.example = example;
this.movieTranses = movieTranses;
}
getter and setter
這裏是MovieTrans:
public class MovieTrans {
public String text;
public MovieTrans(String text){
this.text = text;
}
getter and setter
我添加的元素的列表:
List<MovieTrans> movieTransList = Arrays.asList(new MovieTrans("Appel me"), new MovieTrans("je t'appel"));
List<Movie> movies = Arrays.asList(new Movie("movie played", movieTransList));
//return a list of MovieTrans
List<MovieTrans> movieTransList1 = movies.stream().map(Movie::getMovieTranses).collect(Collectors.toList());
我有這個編譯器錯誤:
Error:(44, 95) java: incompatible types: inference variable T has incompatible bounds
equality constraints: MovieTrans
lower bounds: java.util.List<MovieTrans>
這是不可能要調用的方法作爲參考在flatMap參數。我用米做 - > m.getMovieTranses()流() – emoleumassi
@emoleumassi編輯。 –