Created
September 30, 2014 06:50
-
-
Save alexanderbartels/61099fdc12a6402b3e30 to your computer and use it in GitHub Desktop.
How to protect a static util class from instantiation in Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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