As a simplified example, I have:
public static final int RUN_TYPE = 1;
if(RUN_TYPE == 1)
{
}
This gives me "Comparing identical" warning at the if. How can I get rid of this warning without disabling the "Comparing identical" warning globally?
As a simplified example, I have:
public static final int RUN_TYPE = 1;
if(RUN_TYPE == 1)
{
}
This gives me "Comparing identical" warning at the if. How can I get rid of this warning without disabling the "Comparing identical" warning globally?
"Comparing identical" warning is because the compiler knows the value, it knows that the RUNT_TYPE has value 1 and you are comparing it with constant 1 which doesn't makes sense.
if you compare it with another variable, which is not constant, the warning won't be there, because the value cannot be determined until runtime.
Example:
int ANOTHER_INT = 1;
if(RUN_TYPE == ANOTHER_INT {}
This won't give you "Comparing identical" warning.
Since you variable is final
there is less than little opportunity for it to change.
Why do you need to test its value ?
EDIT
... then pass a property on the java command line using the -D
flag and read this property in your code e.g.
if ( "WHATEVER".equals(System.getProperty("myproperty", "default_value"))) {
...
}