Why does the Collections class contain standalone (static) methods, instead of them being added to the List interface?

前端 未结 5 1165
臣服心动
臣服心动 2021-02-19 12:07

For all the methods in Collections that take a List as their first argument, why aren\'t those methods simply part of the List interface?

My intuition is: given a List

5条回答
  •  猫巷女王i
    2021-02-19 12:09

    They are utility methods and not core List functionality. The List interface would just get bloated if you added every possible operation you could do on a List. And the operations in Collections do not need to know about the internals of a List, they operate on the public interface so can happily live in an external class.

提交回复
热议问题