Managing highly repetitive code and documentation in Java

后端 未结 9 669
南旧
南旧 2020-11-30 22:53

Highly repetitive code is generally a bad thing, and there are design patterns that can help minimize this. However, sometimes it\'s simply inevitable due to the constraints

9条回答
  •  猫巷女王i
    2020-11-30 23:15

    A lot of this kind of repetition can now be avoided thanks to generics. They're a godsend when writing the same code where only the types change.

    Sadly though, I think generic arrays are still not very well supported. For now at least, use containers that allow you to take advantage of generics. Polymorphism is also a useful tool to reduce this kind of code duplication.

    To answer your question about how to handle code that absolutely must be duplicated... Tag each instance with easily searchable comments. There are some java preprocessors out there, that add C-style macros. I think I remember netbeans having one.

提交回复
热议问题