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!
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
Lucas Santos19,315 Points
Interface and Implementation?
So i'v been going through the Java Data Structure course and one thing I did not understand was when Craig was talking about Lists and Sets.
List<String> fruits = new ArrayList<>(); Set<String> people = new HashSet<>();
Craig in couple of the videos now keeps saying "We add the interface on the left and Implementation on the right"
I do not understand that.
So List & Set are both interfaces while ArrayList & HashSet are implementations. To my understanding Interfaces are a lot like a class but with contracts that you can imbed in a class with the keyword implements myInterface.
So this is where I am getting confused because why would you use an Interface as a type of an instance variable??
And not to mention that I do not know what an implementation is and what it's purpose is.
Can someone please explain Interface and Implementation?
Grigorij Schleifer10,365 Points
I had a similar question times ago. Craig and lain explain the topic very good !