Welcome to the Treehouse Community
Looking to learn something new?
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,363 Points
I had a similar question times ago. Craig and lain explain the topic very good !