Java

Java

Made by DeepSource

Use of member identifier that is a keyword in later Java versions JAVA-S0050

Bug risk
Major

This identifier is reserved as a keyword in later versions of Java. If/when this code is migrated to a newer Java version, it will not compile unless the identifier is renamed.

Keywords such as enum, var or assert were not always keywords. Older code that uses them as identifiers may break when ported to newer Java versions.

The following tokens used to be treated as identifiers but are now treated as keywords:

  • strictfp - Since Java 1.2. Used to make floating point operations more portable across all Java platforms.
  • assert - Since Java 1.4
  • enum - Since Java 1.5

The tokens listed below on the other hand are "restricted", and only behave as keywords in certain contexts. It is still possible to use them as identifiers otherwise.

  • yield - Since Java 13. Allows the return value of switch blocks to be assigned to a variable.
  • record - Since Java 14. Used to declare record classes.
  • var - Since Java 10. Used to declare local variables. The type of the value is inferred.
  • sealed - Since Java 15. Marks an interface as being implemented by a restricted set of classes.
  • permits - Since Java 15. Used to specify the set of classes/interfaces which can directly implement/extend a particular sealed interface.

References