Why not always use Generics?

前端 未结 5 1340
星月不相逢
星月不相逢 2021-01-02 05:42

I am reading existing posts on Generics at SO. If Generics has so many advantages like Type safety, no overhead of boxing/unboxing and it is fast, why not always use it? Why

5条回答
  •  走了就别回头了
    2021-01-02 06:02

    Generics may be fast and type safe, but also add complexity (another dimension which can vary and must be understood by programmers). Who is going to maintain your code? Not every trick with generics (or lambdas, or dependency injection, or...) is worth it. Think about what problem you are going to solve, and what parts of that problem may change in the future. Design for those cases. The optimally flexible software is too complex to be maintained by mortal programmers.

提交回复
热议问题