Programming languages evolve over time, and new versions of Java introduce additional keywords. If future keywords are used in the current code, it can create compatibility issues when transitioning to newer versions of Java. The code may fail to compile or behave unexpectedly due to conflicts with newly introduced keywords.
The following keywords are marked as invalid identifiers:
Keyword | Added in version |
---|---|
|
9 |
|
5.0 |
assert
and strictfp
are another example of valid identifiers which became keywords in later versions, but are not
supported by this rule.
Rename the identifiers that use Java keywords.
public class MyClass { int enum = 42; // Noncompliant String _ = ""; // Noncompliant }
public class MyClass { int magic = 42; // Noncompliant String s = ""; // Noncompliant }