Should i return List or ArrayList

后端 未结 4 861
时光取名叫无心
时光取名叫无心 2020-12-31 10:41

I find myself agreeing to return an interface instead of a concrete class.

The reason is simple, i want loose coupling.

But will there be other implication

4条回答
  •  醉话见心
    2020-12-31 11:39

    Implication is that you wont be able to call methods of ArrayList that are not methods of List interface for the objects returned.

    But if the object is an ArrayList you can do a cast.

提交回复
热议问题