Compilation error when using var in Java submissions on LeetCode
0 reputation · 27 Mar 2021, 02:31 UTC
Users who wish to write concise Java code with features introduced after Java 8, such as local‑variable type inference (var), switch expressions, or the HttpClient API, encounter compilation failures when submitting to LeetCode. The platform’s execution environment currently defaults to OpenJDK 8, which does not recognize these newer language constructs, leading to errors like 'cannot find symbol' or 'source version 1.8' messages. While the FAQ confirms the JDK 8 baseline, LeetCode has not announced a timeline for upgrading to a newer JDK, leaving the compatibility decision unresolved. This creates uncertainty for developers who rely on modern idioms and wonder whether they can enable a higher language level or must restrict themselves to Java 8 syntax.
- Can a user select a newer Java version for their submissions on LeetCode?
- Is there any announced plan or roadmap for upgrading LeetCode’s Java compiler beyond JDK 8?
- Are there supported workarounds that allow using var or switch expressions without triggering compilation errors?