0

we always use this code

List mylist=new ArrayList();

I look this statement into deep and i found that mylist is an interface reference which is referring to the ArrayList which is a class.I found(on internet) that there is some benefits of it like Loose coupling ,memory management etc.But How ?what are the benefits of using interface refernce?

1 Answers1

1

There is no memory management benefits.

However, using the interface Type allows you to make use of polymorphism. Here, it means you can use any class inheriting List as a working implementation replacement.

This is allowing loose coupling because you are not tied with ONE and ONLY list implementation.

https://docs.oracle.com/javase/tutorial/java/IandI/polymorphism.html

https://docs.oracle.com/javase/tutorial/java/concepts/interface.html

Hello_world
  • 303
  • 2
  • 11
  • i had seen the link but it just only tell about the Interface .I have still some doubt why we are using the Interface reference? – Deepak Sharma Feb 10 '16 at 13:06