I read "Effective Java" by Joshua Bloch and removed the "Anti-pattern" with a persistent interface from our application. The trick is to use the Non-instantiable util class, whose constructor is private, and define all the constants as "public static final"
I need to extend this constant util class. I can only do this when changing the constructor to protected.
Can anyone suggest a better way.
public class Constants {
private Constants () {}
public static final String MyString = "MyString";
}
public class MyConstants extends Constants {
private MyConstants () {}
public static final String MySecondString = "MySecondString";
}
source
share