Use interface or type for variable definition in java?

List is an Interface, whereas ArrayList is an implementation of that interface.

The second is better because it means you can change your ArrayList for another implementation of List later without needing to change the rest of your application. You may want to do this for performance reasons, or because of other aspects of the behaviour of the List implementation that you have chosen/will choose.

Leave a Comment