Hi, I read "Effective Java" by Joshua Bloch and removed the 'Constant Interface anti-pattern' from our application. The trick is to use Non-instantiable util class whose constructor is private, and define all the constants as 'public static final'
I have to extend the this constant util class. I can only do this when I change the constructor to protected.
Could somebody suggest a better way.
public class Constants {
private Constants () {} // Prevent instantiation
public static final String MyString = "MyString";
}
public class MyConstants extends Constants {
private MyConstants () {} // Compiler error : Implicit super constructor Constants() is not visible.
public static final String MySecondString = "MySecondString";
}