Do not declare it abstract ; declare the constructor private , so no one, not even a subclass, can instantiate your utility class.
You can declare your class final , although if all the constructors are private , then no one can subclass it anyway.
To borrow the idea from Pshemo's comment in another answer, throw a RuntimeException in the constructor to prevent the setAccessible method from reflecting AccessibleObject from resolving the instance:
public class MyUtility { private MyUtility() { throw new RuntimeException("Instantiation of MyUtility is not allowed!"); } public static void utilityMethod() {
source share