I have a class declaring constants for my application
public class GroupConstants { .. public static final int INTEGER_VALUE = 1; public static final int LONG_VALUE = 2; public static final int STRING_VALUE = 3; .. }
The code has a set of switch statements
private static Object getValue(String stringValue, Parameter parameter) throws InvalidPatternException { Object result=null; switch (parameter.getDataType()) { case GroupConstants.STRING_VALUE:
I want to reorganize constant int values that will be represented by an enumeration
public enum DataType { UNKNOWN_VALUE(0,"unknown"), INTEGER_VALUE(1,"integer"), LONG_VALUE(2,"long"), STRING_VALUE(3,"string"), BOOLEAN_VALUE(4,"boolean"), .. }
so my code might look like this:
@Deprecated public static final int INTEGER_VALUE = DataType.INTEGER_VALUE.getId();
and overtime, I can change my switch statements. When I change the static final reference to int to indicate an enumeration, all of my switch statements are interrupted.
[javac] /home/assure/projects/tp/main/src/a/b/c/DDDDDManagerBean.java:1108: constant expression required [javac] case GroupConstants.INTEGER_VALUE: [javac] ^ [javac] /home/assure/projects/tp/main/src/a/b/c/ParameterComponent.java:203: constant expression required [javac] case GroupConstants.INTEGER_VALUE: [javac] ^ [javac] /home/assure/projects/tp/main/src/a/b/c/ParameterComponent.java:268: constant expression required [javac] case GroupConstants.INTEGER_VALUE: [javac] ^ [javac] /home/assure/projects/tp/main/src/a/b/c/ParameterComponent.java:316: constant expression required [javac] case GroupConstants.INTEGER_VALUE: [javac] ^ [javac] /home/assure/projects/tp/main/src/a/b/c/ParameterComponent.java:436: constant expression required [javac] case GroupConstants.INTEGER_VALUE:
I don’t want to be forced to change all the switches, so is there any clean work there?
java
emeraldjava
source share