APIdia Launch Partner
Top Description Fields Constructors Methods
javax.lang.model

public final Enum SourceVersion

extends Enum<SourceVersion>
Class Inheritance

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
java.lang.reflect.ClassFileFormatVersion

Field Summary

Modifier and TypeField and Description
private static final SourceVersion
public static final SourceVersion
RELEASE_0

The original version.

public static final SourceVersion
RELEASE_1

The version introduced by the Java Platform 1.1.

public static final SourceVersion
RELEASE_10

The version introduced by the Java Platform, Standard Edition 10.

public static final SourceVersion
RELEASE_11

The version introduced by the Java Platform, Standard Edition 11.

public static final SourceVersion
RELEASE_12

The version introduced by the Java Platform, Standard Edition 12.

public static final SourceVersion
RELEASE_13

The version introduced by the Java Platform, Standard Edition 13.

public static final SourceVersion
RELEASE_14

The version introduced by the Java Platform, Standard Edition 14.

public static final SourceVersion
RELEASE_15

The version introduced by the Java Platform, Standard Edition 15.

public static final SourceVersion
RELEASE_16

The version introduced by the Java Platform, Standard Edition 16.

public static final SourceVersion
RELEASE_17

The version introduced by the Java Platform, Standard Edition 17.

public static final SourceVersion
RELEASE_18

The version introduced by the Java Platform, Standard Edition 18.

public static final SourceVersion
RELEASE_19

The version introduced by the Java Platform, Standard Edition 19.

public static final SourceVersion
RELEASE_2

The version introduced by the Java 2 Platform, Standard Edition, v 1.2.

public static final SourceVersion
RELEASE_20

The version introduced by the Java Platform, Standard Edition 20.

public static final SourceVersion
RELEASE_21

The version introduced by the Java Platform, Standard Edition 21.

public static final SourceVersion
RELEASE_22

The version introduced by the Java Platform, Standard Edition 22.

public static final SourceVersion
RELEASE_23

The version introduced by the Java Platform, Standard Edition 23.

public static final SourceVersion
RELEASE_24

The version introduced by the Java Platform, Standard Edition 24.

public static final SourceVersion
RELEASE_25

The version introduced by the Java Platform, Standard Edition 25.

public static final SourceVersion
RELEASE_26

The version introduced by the Java Platform, Standard Edition 26.

public static final SourceVersion
RELEASE_27

The version introduced by the Java Platform, Standard Edition 27.

public static final SourceVersion
RELEASE_3

The version introduced by the Java 2 Platform, Standard Edition, v 1.3.

public static final SourceVersion
RELEASE_4

The version introduced by the Java 2 Platform, Standard Edition, v 1.4.

public static final SourceVersion
RELEASE_5

The version introduced by the Java 2 Platform, Standard Edition 5.0.

public static final SourceVersion
RELEASE_6

The version introduced by the Java Platform, Standard Edition 6.

public static final SourceVersion
RELEASE_7

The version introduced by the Java Platform, Standard Edition 7.

public static final SourceVersion
RELEASE_8

The version introduced by the Java Platform, Standard Edition 8.

public static final SourceVersion
RELEASE_9

The version introduced by the Java Platform, Standard Edition 9.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static SourceVersion
public static boolean

Returns:

true if this string is a syntactically valid identifier or keyword, false otherwise.
isIdentifier
(CharSequence
the string to check
name
)

Returns whether or not name is a syntactically valid identifier (simple name) or keyword in the latest source version.

public static boolean

Returns:

true if s is a keyword, a boolean literal, or the null literal, false otherwise.
isKeyword
(CharSequence
the string to check
s
)

Returns whether or not s is a keyword, a boolean literal, or the null literal in the latest source version.

public static boolean

Returns:

true if s is a keyword, a boolean literal, or the null literal, false otherwise.
isKeyword
(CharSequence
the string to check
s
,
SourceVersion
the version to use
version
)

Returns whether or not s is a keyword, a boolean literal, or the null literal in the given source version.

public static boolean

Returns:

true if this string is a syntactically valid name, false otherwise.
isName
(CharSequence
the string to check
name
)

Returns whether or not name is a syntactically valid qualified name in the latest source version.

public static boolean

Returns:

true if this string is a syntactically valid name, false otherwise.
isName
(CharSequence
the string to check
name
,
SourceVersion
the version to use
version
)

Returns whether or not name is a syntactically valid qualified name in the given source version.

public static SourceVersion

Returns:

the latest source version that can be modeled
latest
()

Returns the latest source version that can be modeled.

public static SourceVersion

Returns:

the latest source version fully supported by the current execution environment
latestSupported
()

Returns the latest source version fully supported by the current execution environment.

public Runtime.Version

Returns:

the least runtime version that supports this source version; otherwise null
runtimeVersion
()

Returns the least runtime version that supports this source version; otherwise null.

public static SourceVersion
public static SourceVersion

Returns:

the latest source version that is usable under the runtime version argument
valueOf
(Runtime.Version
runtime version to map to a source version
rv
)

Returns the latest source version that is usable under the runtime version argument.

public static SourceVersion[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

latestSupportedback to summary
private static final SourceVersion latestSupported
RELEASE_0back to summary
public static final SourceVersion RELEASE_0

The original version. The language described in The Java Language Specification, First Edition.

RELEASE_1back to summary
public static final SourceVersion RELEASE_1

The version introduced by the Java Platform 1.1. The language is RELEASE_0 augmented with nested classes as described in the 1.1 update to The Java Language Specification, First Edition.

RELEASE_10back to summary
public static final SourceVersion RELEASE_10

The version introduced by the Java Platform, Standard Edition 10. Additions in this release include local-variable type inference (var).

Since
10
See Also
The Java Language Specification, Java SE 10 Edition, JEP 286: Local-Variable Type Inference
RELEASE_11back to summary
public static final SourceVersion RELEASE_11

The version introduced by the Java Platform, Standard Edition 11. Additions in this release include local-variable syntax for lambda parameters.

Since
11
See Also
The Java Language Specification, Java SE 11 Edition, JEP 323: Local-Variable Syntax for Lambda Parameters
RELEASE_12back to summary
public static final SourceVersion RELEASE_12

The version introduced by the Java Platform, Standard Edition 12. No major changes from the prior release.

Since
12
See Also
The Java Language Specification, Java SE 12 Edition
RELEASE_13back to summary
public static final SourceVersion RELEASE_13

The version introduced by the Java Platform, Standard Edition 13. No major changes from the prior release.

Since
13
See Also
The Java Language Specification, Java SE 13 Edition
RELEASE_14back to summary
public static final SourceVersion RELEASE_14

The version introduced by the Java Platform, Standard Edition 14. Additions in this release include switch expressions.

Since
14
See Also
The Java Language Specification, Java SE 14 Edition, JEP 361: Switch Expressions
RELEASE_15back to summary
public static final SourceVersion RELEASE_15

The version introduced by the Java Platform, Standard Edition 15. Additions in this release include text blocks.

Since
15
See Also
The Java Language Specification, Java SE 15 Edition, JEP 378: Text Blocks
RELEASE_16back to summary
public static final SourceVersion RELEASE_16

The version introduced by the Java Platform, Standard Edition 16. Additions in this release include records and pattern matching for instanceof.

Since
16
See Also
The Java Language Specification, Java SE 16 Edition, JEP 394: Pattern Matching for instanceof, JEP 395: Records
RELEASE_17back to summary
public static final SourceVersion RELEASE_17

The 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
The Java Language Specification, Java SE 17 Edition, JEP 306: Restore Always-Strict Floating-Point Semantics, JEP 409: Sealed Classes
RELEASE_18back to summary
public static final SourceVersion RELEASE_18

The version introduced by the Java Platform, Standard Edition 18. No major changes from the prior release.

Since
18
See Also
The Java Language Specification, Java SE 18 Edition
RELEASE_19back to summary
public static final SourceVersion RELEASE_19

The version introduced by the Java Platform, Standard Edition 19. No major changes from the prior release.

Since
19
See Also
The Java Language Specification, Java SE 19 Edition
RELEASE_2back to summary
public static final SourceVersion RELEASE_2

The version introduced by the Java 2 Platform, Standard Edition, v 1.2. The language described in The Java Language Specification, Second Edition, which includes the strictfp modifier.

RELEASE_20back to summary
public static final SourceVersion RELEASE_20

The version introduced by the Java Platform, Standard Edition 20. No major changes from the prior release.

Since
20
See Also
The Java Language Specification, Java SE 20 Edition
RELEASE_21back to summary
public static final SourceVersion RELEASE_21

The version introduced by the Java Platform, Standard Edition 21. Additions in this release include record patterns and pattern matching for switch.

Since
21
See Also
The Java Language Specification, Java SE 21 Edition, JEP 440: Record Patterns, JEP 441: Pattern Matching for switch
RELEASE_22back to summary
public static final SourceVersion RELEASE_22

The version introduced by the Java Platform, Standard Edition 22. Additions in this release include unnamed variables and unnamed patterns.

Since
22
See Also
The Java Language Specification, Java SE 22 Edition, JEP 456: Unnamed Variables & Patterns
RELEASE_23back to summary
public static final SourceVersion RELEASE_23

The version introduced by the Java Platform, Standard Edition 23.

Since
23
See Also
The Java Language Specification, Java SE 23 Edition
RELEASE_24back to summary
public static final SourceVersion RELEASE_24

The version introduced by the Java Platform, Standard Edition 24.

Since
24
See Also
The Java Language Specification, Java SE 24 Edition
RELEASE_25back to summary
public static final SourceVersion RELEASE_25

The version introduced by the Java Platform, Standard Edition 25. Additions in this release include module import declarations, compact source files and instance main methods, and flexible constructor bodies.

Since
25
See Also
The Java Language Specification, Java SE 25 Edition, JEP 511: Module Import Declarations, JEP 512: Compact Source Files and Instance Main Methods, JEP 513: Flexible Constructor Bodies
RELEASE_26back to summary
public static final SourceVersion RELEASE_26

The version introduced by the Java Platform, Standard Edition 26.

Since
26
See Also
The Java Language Specification, Java SE 26 Edition
RELEASE_27back to summary
public static final SourceVersion RELEASE_27

The version introduced by the Java Platform, Standard Edition 27.

Since
27
See Also
The Java Language Specification, Java SE 27 Edition
RELEASE_3back to summary
public static final SourceVersion RELEASE_3

The version introduced by the Java 2 Platform, Standard Edition, v 1.3. No major changes from RELEASE_2.

RELEASE_4back to summary
public static final SourceVersion RELEASE_4

The version introduced by the Java 2 Platform, Standard Edition, v 1.4. Added a simple assertion facility.

See Also
JSR 41: A Simple Assertion Facility
RELEASE_5back to summary
public static final SourceVersion RELEASE_5

The 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, enhanced for loop, and hexadecimal floating-point literals.

See Also
JSR 14: Add Generic Types To The Java™ Programming Language, JSR 175: A Metadata Facility for the Java™ Programming Language, JSR 201: Extending the Java™ Programming Language with Enumerations, Autoboxing, Enhanced for loops and Static Import
RELEASE_6back to summary
public static final SourceVersion RELEASE_6

The version introduced by the Java Platform, Standard Edition 6. No major changes from RELEASE_5.

See Also
The Java Language Specification, Third Edition
RELEASE_7back to summary
public static final SourceVersion RELEASE_7

The 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
The Java Language Specification, Java SE 7 Edition, JSR 334: Small Enhancements to the Java™ Programming Language
RELEASE_8back to summary
public static final SourceVersion RELEASE_8

The version introduced by the Java Platform, Standard Edition 8. Additions in this release include lambda expressions and default methods.

Since
1.8
See Also
The Java Language Specification, Java SE 8 Edition, JSR 335: Lambda Expressions for the Java™ Programming Language
RELEASE_9back to summary
public static final SourceVersion RELEASE_9

The 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
The Java Language Specification, Java SE 9 Edition, JSR 376: Java™ Platform Module System, JEP 213: Milling Project Coin

Constructor Detail

SourceVersionback to summary
private SourceVersion()

Method Detail

getLatestSupportedback to summary
private static SourceVersion getLatestSupported()
isIdentifierback to summary
public static boolean isIdentifier(CharSequence name)

Returns whether or not name is a syntactically valid identifier (simple name) or keyword in the latest source version. The method returns true if the name consists of an initial character for which Character#isJavaIdentifierStart(int) returns true, followed only by characters for which Character#isJavaIdentifierPart(int) returns true. This pattern matches regular identifiers, keywords, contextual keywords, boolean literals, and the null literal. The method returns false for all other strings.

Parameters
name:CharSequence

the string to check

Returns:boolean

true if this string is a syntactically valid identifier or keyword, false otherwise.

Java Language Specification
3.8 Identifiers
isKeywordback to summary
public static boolean isKeyword(CharSequence s)

Returns whether or not s is a keyword, a boolean literal, or the null literal in the latest source version. This method returns false for contextual keywords.

Parameters
s:CharSequence

the string to check

Returns:boolean

true if s is a keyword, a boolean literal, or the null literal, false otherwise.

Java Language Specification
3.9 Keywords, 3.10.3 Boolean Literals, 3.10.8 The Null Literal
isKeywordback to summary
public static boolean isKeyword(CharSequence s, SourceVersion version)

Returns whether or not s is a keyword, a boolean literal, or the null literal in the given source version. This method returns false for contextual keywords.

Parameters
s:CharSequence

the string to check

version:SourceVersion

the version to use

Returns:boolean

true if s is a keyword, a boolean literal, or the null literal, false otherwise.

Since
9
Java Language Specification
3.9 Keywords, 3.10.3 Boolean Literals, 3.10.8 The Null Literal
isNameback to summary
public static boolean isName(CharSequence name)

Returns whether or not name is 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. Unlike isIdentifier, this method returns false for keywords, boolean literals, and the null literal in any segment. This method returns true for contextual keywords.

Parameters
name:CharSequence

the string to check

Returns:boolean

true if this string is a syntactically valid name, false otherwise.

Java Language Specification
3.9 Keywords, 6.2 Names and Identifiers
isNameback to summary
public static boolean isName(CharSequence name, SourceVersion version)

Returns whether or not name is 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. Unlike isIdentifier, this method returns false for keywords, boolean literals, and the null literal in any segment. This method returns true for contextual keywords.

Parameters
name:CharSequence

the string to check

version:SourceVersion

the version to use

Returns:boolean

true if this string is a syntactically valid name, false otherwise.

Since
9
Java Language Specification
3.9 Keywords, 6.2 Names and Identifiers
latestback to summary
public static SourceVersion latest()

Returns the latest source version that can be modeled.

Returns:SourceVersion

the latest source version that can be modeled

latestSupportedback to summary
public static SourceVersion latestSupported()

Returns the latest source version fully supported by the current execution environment. RELEASE_9 or 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 from 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 the latestSupported release, which may be earlier than the latest release.

Returns:SourceVersion

the latest source version fully supported by the current execution environment

runtimeVersionback to summary
public Runtime.Version runtimeVersion()

Returns the least runtime version that supports this source version; otherwise null. 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 to RELEASE_6 have non-null results.

Returns:Runtime.Version

the least runtime version that supports this source version; otherwise null

Since
18
valueOfback to summary
public static SourceVersion valueOf(String name)
valueOfback to summary
public static SourceVersion valueOf(Runtime.Version rv)

Returns 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, an IllegalArgumentException is 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"))
SourceVersion.valueOf(Runtime.Version.parse("17"))
Parameters
rv:Runtime.Version

runtime version to map to a source version

Returns:SourceVersion

the latest source version that is usable under the runtime version argument

Exceptions
IllegalArgumentException:
if the feature of version argument is greater than the feature of the platform version.
Since
18
valuesback to summary
public static SourceVersion[] values()