Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java

I didn't understand something that Craig said.

At 0:40, in this video Craig Dennis says that "we always wanna return the list interface not the implementation because in the future we could change the implementation if we wanted to and we wouldn't break code the code that uses this method." What does this exactly mean? I didn't understand a word of it. Please explain.

1 Answer

In the example: List<String> results = new ArrayList<>();

List<String> is the interface and ArrayList<>() is the implementation. In this case you want to return List<String> because that allows you to implement it into a different class like a HashSet instead of a ArrayList, for example.