I saw some codes in slf4j as show below. I don't know why to avoid constant folding in here. Is it necessary to do that? or just best practice. what's the benefit of doing this?
/** * Declare the version of the SLF4J API this implementation is compiled against. * The value of this field is usually modified with each release. */ // to avoid constant folding by the compiler, this field must *not* be final public static String REQUESTED_API_VERSION = "1.6"; // !final**
finalbut pass the value through a method ("1.6".toString()) or add some code to prevent it being a compile-time constant yet not add any unnecessary bytecode (null!=null?"": "1.6").public static String REQUESTED_API_VERSION = new String("1."+"6"); //new String is not literal, so it'll result in GETSTATIC