1. /**
  2.   * getTopMovies method, get all top rated movies from list
  3.   * @param <T> The type of the list
  4.   * @param movieList List with all the rated movies
  5.   * @return Returns a list with only the top movies
  6.   */
  7. public <T> MovieList<T> getTopMovies (MovieList<? extends Movie> movieList)
  8. {
  9.  
  10. MovieList<Movie> topMovieList = new MovieList<Movie>();
  11.  
  12. for (Movie movie : movieList)
  13. {
  14. if (movie.rate > 4)
  15. topMovieList.add(movie); // OK!, since all types are known.
  16. }
  17. return (MovieList<T>) topMovieList; //Cast to right Type
  18. }