Should i return List or ArrayList

后端 未结 4 851
时光取名叫无心
时光取名叫无心 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:27

    The only reason to return concrete class could be if caller needs to be aware of this concrete implementation or, possibly, additional interfaces on concrete implementation. For example, in Android, you often have to use ArrayList because framework does not know how to properly serialize generic list interface.

提交回复
热议问题