Managing highly repetitive code and documentation in Java

后端 未结 9 661
南旧
南旧 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条回答
  •  眼角桃花
    2020-11-30 23:30

    Java primitive types screw you, especially when it comes to arrays. If you're specifically asking about code involving primitive types, then I would say just try to avoid them. The Object[] method is sufficient if you use the boxed types.

    In general, you need lots of unit tests and there really isn't anything else to be done, other than resorting to reflection. Like you said, it's another subject entirely, but don't be too afraid of reflection. Write the DRYest code you can first, then profile it and determine if the reflection performance hit is really bad enough to warrant writing out and maintaining the extra code.

提交回复
热议问题