How do you define a class of constants in Java? -


Suppose you need to define a square, which does this, it keeps the constant.

  public static final string SOME_CONST = "SOME_VALUE";  
  • Abstract class
  • Last class
  • - I'm not going to use anom, I am not telling anything, just a few I collect the constants that are not related to each other in any way.

    Interface - I'm not making any class applicable to the interface. Just want to use the interface to make constant calls: ISomeInterface.SOME_CONST .

  • Use one last square for simplicity then you can re-use your values ​​in another category Can use a static import for

      public end class mallows {public static final string VALUE1 = "foo"; Public static final string VALUE2 = "bar"; }  

    In another class:

      Fixed static import. * // ... if (variable.equals (VALUE1)) {// .. ..}  

    Comments