The Code
class MovieLister…
public Movie[] moviesDirectedBy(String arg) {
List allMovies = finder.findAll();
for (Iterator it = allMovies.iterator(); it.hasNext();) {
Movie movie = (Movie) it.next();
if (!movie.getDirector().equals(arg)) it.remove();
}
return (Movie[]) allMovies.toArray(new Movie[allMovies.size()]);
}
The Questions
Why is the Return Statement Casting the Type Movie[]?
Resources
- This class came from https://martinfowler.com/articles/injection.html
- Note: this article was written in 2004.
- Java 1.0 was first released in 1996
- The next major release was in Sept 2004 with Java 5
- Some of the questions are related to the fact that the article was written in early versions of Java.
- Why is it called a “container”?
