i am trying to set a string value(for variable env) as follows for all the objects:-
public class example{
private String env;
public String getEnv() {
return env;
}
public void setEnv(String env) {
this.env = "IN";
}
}
is it the right way to Hard code the variable value or any better way to do it.
Thanks.
解决方案
Create a constants file which contains all the Strings necessary. Make
the String public static and final. Then use it in your code
example: this.env = ConstantsFile.IN; // tomorrow you can change its value to "pinnnn" only in the Constants file and not worry about changing every other filed that uses "IN" (now "pinnnn" :) ).
this keeps your code clean and reduces dependency.