iamukt iamukt - 1 year ago 89
Java Question

Separate Interface or Utility class for defining constants in core java project

I am working on a project (using JDK7) which has 30 to 40 constants. These constants are being used by many classes of my project. I want to separate these constants into a single file. Which type of file should I prefer?, Interface or Utility class, I am thinking of using interface. Would it be appropriate ?

Answer Source

According to the SonarQube rules Constants should not be defined in interfaces

Example from Eclipse with sonar binding

You should use a class or an enum.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download