This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Originally posted by henri henri: I just learned that it is better programming practice if I change TreeMap at the beginning of the second line of code to Map.
Map<String, FilmBean>filmBeans = new TreeMap<String, FilmBean>();
after I do this, I get a compiler error for the return statement at the end of the method.
Well, you can't make the change and everything magically still works. You have to change your method to return a Map instead of a TreeMap. And you have to change all the places in your program to use a Map instead of a TreeMap.
To sum up some previous responses, yes it's good programming practice to "program to the interface" when possible. In your example, it's more important for your getFilmBeansByLetter method to have return type Map (or Map<String FilmBean> in Java 1.5) that for its local value filmBeans to have type Map<String FilmBean> versus TreeMap<String FilmBean>, although the two can go hand-in-hand.