Enum Class SourceVersion
- All Implemented Interfaces:
- Serializable,- Comparable<SourceVersion>,- Constable
Source versions of the Java programming language.
 See the appropriate edition of
 The Java Language Specification
 for information about a particular source version.
 
Note that additional source version constants will be added to model future releases of the language.
- Since:
- 1.6
- See Also:
- 
Nested Class SummaryNested classes/interfaces declared in class java.lang.EnumEnum.EnumDesc<E extends Enum<E>>
- 
Enum Constant SummaryEnum ConstantsEnum ConstantDescriptionThe original version.The version introduced by the Java Platform 1.1.The version introduced by the Java Platform, Standard Edition 10.The version introduced by the Java Platform, Standard Edition 11.The version introduced by the Java Platform, Standard Edition 12.The version introduced by the Java Platform, Standard Edition 13.The version introduced by the Java Platform, Standard Edition 14.The version introduced by the Java Platform, Standard Edition 15.The version introduced by the Java Platform, Standard Edition 16.The version introduced by the Java Platform, Standard Edition 17.The version introduced by the Java Platform, Standard Edition 18.The version introduced by the Java Platform, Standard Edition 19.The version introduced by the Java 2 Platform, Standard Edition, v 1.2.The version introduced by the Java Platform, Standard Edition 20.The version introduced by the Java Platform, Standard Edition 21.The version introduced by the Java Platform, Standard Edition 22.The version introduced by the Java Platform, Standard Edition 23.The version introduced by the Java 2 Platform, Standard Edition, v 1.3.The version introduced by the Java 2 Platform, Standard Edition, v 1.4.The version introduced by the Java 2 Platform, Standard Edition 5.0.The version introduced by the Java Platform, Standard Edition 6.The version introduced by the Java Platform, Standard Edition 7.The version introduced by the Java Platform, Standard Edition 8.The version introduced by the Java Platform, Standard Edition 9.
- 
Method SummaryModifier and TypeMethodDescriptionstatic booleanisIdentifier(CharSequence name) Returns whether or notnameis a syntactically valid identifier (simple name) or keyword in the latest source version.static booleanReturns whether or notsis a keyword, boolean literal, or null literal in the latest source version.static booleanisKeyword(CharSequence s, SourceVersion version) Returns whether or notsis a keyword, boolean literal, or null literal in the given source version.static booleanisName(CharSequence name) Returns whether or notnameis a syntactically valid qualified name in the latest source version.static booleanisName(CharSequence name, SourceVersion version) Returns whether or notnameis a syntactically valid qualified name in the given source version.static SourceVersionlatest()Returns the latest source version that can be modeled.static SourceVersionReturns the latest source version fully supported by the current execution environment.Returns the least runtime version that supports this source version; otherwisenull.static SourceVersionReturns the latest source version that is usable under the runtime version argument.static SourceVersionReturns the enum constant of this class with the specified name.static SourceVersion[]values()Returns an array containing the constants of this enum class, in the order they are declared.
- 
Enum Constant Details- 
RELEASE_0The original version. The language described in The Java Language Specification, First Edition.
- 
RELEASE_1The version introduced by the Java Platform 1.1. The language isRELEASE_0augmented with nested classes as described in the 1.1 update to The Java Language Specification, First Edition.
- 
RELEASE_2The version introduced by the Java 2 Platform, Standard Edition, v 1.2. The language described in The Java Language Specification, Second Edition, which includes thestrictfpmodifier.
- 
RELEASE_3The version introduced by the Java 2 Platform, Standard Edition, v 1.3. No major changes fromRELEASE_2.
- 
RELEASE_4The version introduced by the Java 2 Platform, Standard Edition, v 1.4. Added a simple assertion facility.- See Also:
 
- 
RELEASE_5The version introduced by the Java 2 Platform, Standard Edition 5.0. The language described in The Java Language Specification, Third Edition. First release to support generics, annotations, autoboxing, var-args, enhancedforloop, and hexadecimal floating-point literals.- See Also:
 
- 
RELEASE_6The version introduced by the Java Platform, Standard Edition 6. No major changes fromRELEASE_5.- See Also:
 
- 
RELEASE_7The version introduced by the Java Platform, Standard Edition 7. Additions in this release include diamond syntax for constructors,try-with-resources, strings in switch, binary literals, and multi-catch.- Since:
- 1.7
- See Also:
 
- 
RELEASE_8The version introduced by the Java Platform, Standard Edition 8. Additions in this release include lambda expressions and default methods.- Since:
- 1.8
- See Also:
 
- 
RELEASE_9The version introduced by the Java Platform, Standard Edition 9. Additions in this release include modules and removal of a single underscore from the set of legal identifier names.- Since:
- 9
- See Also:
 
- 
RELEASE_10The version introduced by the Java Platform, Standard Edition 10. Additions in this release include local-variable type inference (var).- Since:
- 10
- See Also:
 
- 
RELEASE_11The version introduced by the Java Platform, Standard Edition 11. Additions in this release include local-variable syntax for lambda parameters.- Since:
- 11
- See Also:
 
- 
RELEASE_12The version introduced by the Java Platform, Standard Edition 12. No major changes from the prior release.- Since:
- 12
- See Also:
 
- 
RELEASE_13The version introduced by the Java Platform, Standard Edition 13. No major changes from the prior release.- Since:
- 13
- See Also:
 
- 
RELEASE_14The version introduced by the Java Platform, Standard Edition 14. Additions in this release include switch expressions.- Since:
- 14
- See Also:
 
- 
RELEASE_15The version introduced by the Java Platform, Standard Edition 15. Additions in this release include text blocks.- Since:
- 15
- See Also:
 
- 
RELEASE_16The version introduced by the Java Platform, Standard Edition 16. Additions in this release include records and pattern matching forinstanceof.- Since:
- 16
- See Also:
 
- 
RELEASE_17The version introduced by the Java Platform, Standard Edition 17. Additions in this release include sealed classes and restoration of always-strict floating-point semantics.- Since:
- 17
- See Also:
 
- 
RELEASE_18The version introduced by the Java Platform, Standard Edition 18. No major changes from the prior release.- Since:
- 18
- See Also:
 
- 
RELEASE_19The version introduced by the Java Platform, Standard Edition 19. No major changes from the prior release.- Since:
- 19
- See Also:
 
- 
RELEASE_20The version introduced by the Java Platform, Standard Edition 20. No major changes from the prior release.- Since:
- 20
- See Also:
 
- 
RELEASE_21The version introduced by the Java Platform, Standard Edition 21. Additions in this release include record patterns and pattern matching forswitch.- Since:
- 21
- See Also:
 
- 
RELEASE_22The version introduced by the Java Platform, Standard Edition 22. Additions in this release include unnamed variables and unnamed patterns.- Since:
- 22
- See Also:
 
- 
RELEASE_23The version introduced by the Java Platform, Standard Edition 23.- Since:
- 23
- See Also:
 
 
- 
- 
Method Details- 
valuesReturns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
 
- 
valueOfReturns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
- name- the name of the enum constant to be returned.
- Returns:
- the enum constant with the specified name
- Throws:
- IllegalArgumentException- if this enum class has no constant with the specified name
- NullPointerException- if the argument is null
 
- 
latestReturns the latest source version that can be modeled.- Returns:
- the latest source version that can be modeled
 
- 
latestSupportedReturns the latest source version fully supported by the current execution environment.RELEASE_9or later must be returned.- API Note:
- This method is included alongside latest()to allow identification of situations where the language model API is running on a platform version different than the latest version modeled by the API. One way that sort of situation can occur is if an IDE or similar tool is using the API to model source version N while running on platform version (N - 1). Running in this configuration is supported by the API. Running an API on platform versions earlier than (N - 1) or later than N may or may not work as an implementation detail. If an annotation processor was generating code to run under the current execution environment, the processor should only use platform features up to thelatestSupportedrelease, which may be earlier than thelatestrelease.
- Returns:
- the latest source version fully supported by the current execution environment
 
- 
isIdentifierReturns whether or notnameis a syntactically valid identifier (simple name) or keyword in the latest source version. The method returnstrueif the name consists of an initial character for whichCharacter.isJavaIdentifierStart(int)returnstrue, followed only by characters for whichCharacter.isJavaIdentifierPart(int)returnstrue. This pattern matches regular identifiers, keywords, contextual keywords, and the literals"true","false","null". The method returnsfalsefor all other strings.- Parameters:
- name- the string to check
- Returns:
- trueif this string is a syntactically valid identifier or keyword,- falseotherwise.
- See Java Language Specification:
- 
3.8 Identifiers
 
- 
isNameReturns whether or notnameis a syntactically valid qualified name in the latest source version. Syntactically, a qualified name is a sequence of identifiers separated by period characters ("."). This method splits the input string into period-separated segments and applies checks to each segment in turn. UnlikeisIdentifier, this method returnsfalsefor keywords, boolean literals, and the null literal in any segment. This method returnstruefor contextual keywords.- Parameters:
- name- the string to check
- Returns:
- trueif this string is a syntactically valid name,- falseotherwise.
- See Java Language Specification:
- 
3.9 Keywords
 6.2 Names and Identifiers
 
- 
isNameReturns whether or notnameis a syntactically valid qualified name in the given source version. Syntactically, a qualified name is a sequence of identifiers separated by period characters ("."). This method splits the input string into period-separated segments and applies checks to each segment in turn. UnlikeisIdentifier, this method returnsfalsefor keywords, boolean literals, and the null literal in any segment. This method returnstruefor contextual keywords.- Parameters:
- name- the string to check
- version- the version to use
- Returns:
- trueif this string is a syntactically valid name,- falseotherwise.
- See Java Language Specification:
- 
3.9 Keywords
 6.2 Names and Identifiers
- Since:
- 9
 
- 
isKeywordReturns whether or notsis a keyword, boolean literal, or null literal in the latest source version. This method returnsfalsefor contextual keywords.- Parameters:
- s- the string to check
- Returns:
- trueif- sis a keyword, or boolean literal, or null literal,- falseotherwise.
- See Java Language Specification:
- 
3.9 Keywords
 3.10.3 Boolean Literals
 3.10.8 The Null Literal
 
- 
isKeywordReturns whether or notsis a keyword, boolean literal, or null literal in the given source version. This method returnsfalsefor contextual keywords.- Parameters:
- s- the string to check
- version- the version to use
- Returns:
- trueif- sis a keyword, or boolean literal, or null literal,- falseotherwise.
- See Java Language Specification:
- 
3.9 Keywords
 3.10.3 Boolean Literals
 3.10.8 The Null Literal
- Since:
- 9
 
- 
valueOfReturns the latest source version that is usable under the runtime version argument. If the runtime version's feature is greater than the feature of the runtime version of the latest source version, anIllegalArgumentExceptionis thrown.Because the source versions of the Java programming language have so far followed a linear progression, only the feature component of a runtime version is queried to determine the mapping to a source version. If that linearity changes in the future, other components of the runtime version may influence the result. - API Note:
- An expression to convert from a string value, for example
 "17", to the corresponding source version,RELEASE_17, is:SourceVersion.valueOf(Runtime.Version.parse("17"))
- Parameters:
- rv- runtime version to map to a source version
- Returns:
- the latest source version that is usable under the runtime version argument
- Throws:
- IllegalArgumentException- if the feature of version argument is greater than the feature of the platform version.
- Since:
- 18
 
- 
runtimeVersionReturns the least runtime version that supports this source version; otherwisenull. The returned runtime version has a feature large enough to support this source version and has no other elements set. Source versions greater than or equal toRELEASE_6have non-nullresults.- Returns:
- the least runtime version that supports this source
 version; otherwise null
- Since:
- 18
 
 
-