A utility class using enum:
public enum StringUtil
{
; // enum terminator
public static void boo ()
{
// ...
}
}
A utility class using class:
public final class StringUtil
{
public static void boo () {
// ...
}
private StringUtil() {
// no-init ctor
}
}
When using Enum
✔ no need for constructor
✔ singleton by default
✖ automatically extends base Enum class
✖ ihnerited Enum methods (name, etc.) available for utility class user
✖ Enum static methods (values, etc.) available for utility class user
No comments:
Post a Comment