Suppose I have a utility class that contains only static methods and variables. eg:
public abstract final class StringUtils
{
public static final String NEW_LINE = System.getProperty("line.separator");
public static boolean isNotNullOrSpace(final String string)
{
return !(string == null || string.length() < 1 || string.trim().length() < 1);
}
}
In this scenario, it makes sense to make the class abstract and final. Annotation, since creating an object of this class will be useless, since all methods are available statically. Final, because a derived class cannot inherit any of this class, since it does not have any non-static element.
C # enables the static modifier for such classes. Why does Java not support this?
source
share