3

I am working in a very huge enterprise application with many modules in side it. I configured the SONAR recently and ran analysis on the project. The following error reported by SONAR is the very common one that I am seeing in every module, wherever I had an interface as follows.

public interface Constants {

    String CONST1 = "CONST1";

    String CONST1 = "CONST2";
}

And the SONAR says:

Move constants to a class or enum.

What is wrong with it, If I need to fix this, I have plenty of files like this.

  • 1
    *Effective Java 2nd Ed* Item 19: "Item 19: Use interfaces only to define types". What does it mean if you implement `Constants` and access `CONST1` on the subtype? – Andy Turner May 25 '16 at 12:20
  • if you want to make use of the constants you basicly use `set(Constants.CONST1)`, but nothing does stop you to write `set("someRandomTextInHere")`, where you´d need to validate against all constants in order to not be able to use non existing values. at least for an `enum` you do only have a limitied set of possible values to set from. – SomeJavaGuy May 25 '16 at 12:22

0 Answers0