Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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.