Skip to content

Instantly share code, notes, and snippets.

@alexanderbartels
Created September 30, 2014 06:50
Show Gist options
  • Save alexanderbartels/61099fdc12a6402b3e30 to your computer and use it in GitHub Desktop.
Save alexanderbartels/61099fdc12a6402b3e30 to your computer and use it in GitHub Desktop.
How to protect a static util class from instantiation in Java
public final class MyUtil {
private static final String MY_CONST = "HalloWelt";
private MyUtil() {
throw new AssertionError("Suppress default constructor for non instantiability");
}
public static int foo() {
return -1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment