Naming convention for utility classes in Java

前端 未结 5 1733
离开以前
离开以前 2021-01-29 21:53

When writing utility classes in Java, what are some good guidelines to follow?

Should packges be \"util\" or \"utils\"? Is it ClassUtil or ClassUtils? When is a class a

5条回答
  •  太阳男子
    2021-01-29 22:36

    I like the convention of just adding "s" to the type name when the type is an interface or a class you don't control. Examples of that in the JDK include Collections and Executors. It's also the convention used in Google Collections.

    When you're dealing with a class you have control over, I'd say utility methods belong on the class itself generally.

提交回复
热议问题