Item 93 of Java Puzzlers (Joshua Bloch) says that you can work round this by preventing the final value from being considered a constant. For example:
public class A {
public static final int INT_VALUE = Integer.valueOf(1000).intValue();
public static final String STRING_VALUE = "foo".toString();
}
Of course none of this is relevant if you don’t have access to the code that defines the constants.
Related Contents:
- Why does a Java class compile differently with a blank line?
- How to add local jar files to a Maven project?
- Why is 2 * (i * i) faster than 2 * i * i in Java?
- How do I tell Maven to use the latest version of a dependency?
- Error:java: invalid source release: 8 in Intellij. What does it mean?
- Maven: Failed to read artifact descriptor
- Make Maven to copy dependencies into target/lib
- Maven: add a dependency to a jar by relative path
- In which language are the Java compiler and JVM written?
- Java 7 language features with Android
- Does the ‘java’ command compile Java programs?
- Bytecode features not available in the Java language
- Java’s Virtual Machine and CLR
- What is the difference between “pom” type dependency with scope “import” and without “import”?
- Add a dependency in Maven
- javac not working in windows command prompt
- What is the –release flag in the Java 9 compiler?
- javac : command not found
- Is it possible to view bytecode of Class file? [duplicate]
- List of dependency jar files in Maven
- Loading Maven dependencies from GitHub [duplicate]
- How can I force Gradle to set the same version for two dependencies?
- How to intentionally cause a custom java compiler warning message?
- Do unused import and objects have a performance impact?
- How to clean old dependencies from maven repositories?
- What are unused/undeclared dependencies in Maven? What to do with them?
- Differences between MSIL and Java bytecode?
- Sort maven dependencies in Eclipse
- Maven Unable to locate the Javac Compiler in:
- Difference between JVM’s LookupSwitch and TableSwitch?
- Why are Java 8 lambdas invoked using invokedynamic?
- What is the $1 in class file names?
- JDK 11.0.2 compilation fails with javac NPE on anonymous parameterized class type inference
- Why does one long string take MORE space than lots of small strings?
- Duplicate class in Kotlin Android
- How to do opposite of of preference attribute android:dependency?
- How to compile multiple java source files in command line
- How to write code in Java 11, but target Java 8 and above?
- Is there a llvm java front end that converts java source to llvm’s intermediate form?
- What is a stack map frame
- Is there a performance difference between Javac debug on and off?
- Make javac treat warnings as errors
- Suppress javac warning “…is internal proprietary API and may be removed in a future release”
- How can I suppress javac warnings about deprecated api?
- In Java 8, why were Arrays not given the forEach method of Iterable?
- Is this valid Java?
- Using internal sun classes with javac
- Why does javac allow some impossible casts and not others?
- What is sjavac, who is it for and how do I use it?
- Are there any specific examples of backward incompatibilities between Java versions?