39 * <p>Note that additional source version constants will be added to
40 * model future releases of the language.
41 *
42 * @author Joseph D. Darcy
43 * @author Scott Seligman
44 * @author Peter von der Ahé
45 * @since 1.6
46 */
47 public enum SourceVersion {
48 /*
49 * Summary of language evolution
50 * 1.1: nested classes
51 * 1.2: strictfp
52 * 1.3: no changes
53 * 1.4: assert
54 * 1.5: annotations, generics, autoboxing, var-args...
55 * 1.6: no changes
56 * 1.7: diamond syntax, try-with-resources, etc.
57 * 1.8: lambda expressions and default methods
58 * 9: modules, small cleanups to 1.7 and 1.8 changes
59 */
60
61 /**
62 * The original version.
63 *
64 * The language described in
65 * <cite>The Java™ Language Specification, First Edition</cite>.
66 */
67 RELEASE_0,
68
69 /**
70 * The version recognized by the Java Platform 1.1.
71 *
72 * The language is {@code RELEASE_0} augmented with nested classes as described in the 1.1 update to
73 * <cite>The Java™ Language Specification, First Edition</cite>.
74 */
75 RELEASE_1,
76
77 /**
78 * The version recognized by the Java 2 Platform, Standard Edition,
133 RELEASE_7,
134
135 /**
136 * The version recognized by the Java Platform, Standard Edition
137 * 8.
138 *
139 * Additions in this release include lambda expressions and default methods.
140 * @since 1.8
141 */
142 RELEASE_8,
143
144 /**
145 * The version recognized by the Java Platform, Standard Edition
146 * 9.
147 *
148 * Additions in this release include modules and removal of a
149 * single underscore from the set of legal identifier names.
150 *
151 * @since 9
152 */
153 RELEASE_9;
154
155 // Note that when adding constants for newer releases, the
156 // behavior of latest() and latestSupported() must be updated too.
157
158 /**
159 * Returns the latest source version that can be modeled.
160 *
161 * @return the latest source version that can be modeled
162 */
163 public static SourceVersion latest() {
164 return RELEASE_9;
165 }
166
167 private static final SourceVersion latestSupported = getLatestSupported();
168
169 private static SourceVersion getLatestSupported() {
170 try {
171 String specVersion = System.getProperty("java.specification.version");
172
173 switch (specVersion) {
174 case "9":
175 case "1.9":
176 return RELEASE_9;
177 case "1.8":
178 return RELEASE_8;
179 case "1.7":
180 return RELEASE_7;
181 case "1.6":
182 return RELEASE_6;
183 }
184 } catch (SecurityException se) {}
185
186 return RELEASE_5;
187 }
188
189 /**
190 * Returns the latest source version fully supported by the
191 * current execution environment. {@code RELEASE_5} or later must
192 * be returned.
193 *
|
39 * <p>Note that additional source version constants will be added to
40 * model future releases of the language.
41 *
42 * @author Joseph D. Darcy
43 * @author Scott Seligman
44 * @author Peter von der Ahé
45 * @since 1.6
46 */
47 public enum SourceVersion {
48 /*
49 * Summary of language evolution
50 * 1.1: nested classes
51 * 1.2: strictfp
52 * 1.3: no changes
53 * 1.4: assert
54 * 1.5: annotations, generics, autoboxing, var-args...
55 * 1.6: no changes
56 * 1.7: diamond syntax, try-with-resources, etc.
57 * 1.8: lambda expressions and default methods
58 * 9: modules, small cleanups to 1.7 and 1.8 changes
59 * 10: to-be-determined changes
60 */
61
62 /**
63 * The original version.
64 *
65 * The language described in
66 * <cite>The Java™ Language Specification, First Edition</cite>.
67 */
68 RELEASE_0,
69
70 /**
71 * The version recognized by the Java Platform 1.1.
72 *
73 * The language is {@code RELEASE_0} augmented with nested classes as described in the 1.1 update to
74 * <cite>The Java™ Language Specification, First Edition</cite>.
75 */
76 RELEASE_1,
77
78 /**
79 * The version recognized by the Java 2 Platform, Standard Edition,
134 RELEASE_7,
135
136 /**
137 * The version recognized by the Java Platform, Standard Edition
138 * 8.
139 *
140 * Additions in this release include lambda expressions and default methods.
141 * @since 1.8
142 */
143 RELEASE_8,
144
145 /**
146 * The version recognized by the Java Platform, Standard Edition
147 * 9.
148 *
149 * Additions in this release include modules and removal of a
150 * single underscore from the set of legal identifier names.
151 *
152 * @since 9
153 */
154 RELEASE_9,
155
156 /**
157 * The version recognized by the Java Platform, Standard Edition
158 * 10.
159 *
160 * @since 10
161 */
162 RELEASE_10;
163
164 // Note that when adding constants for newer releases, the
165 // behavior of latest() and latestSupported() must be updated too.
166
167 /**
168 * Returns the latest source version that can be modeled.
169 *
170 * @return the latest source version that can be modeled
171 */
172 public static SourceVersion latest() {
173 return RELEASE_10;
174 }
175
176 private static final SourceVersion latestSupported = getLatestSupported();
177
178 private static SourceVersion getLatestSupported() {
179 try {
180 String specVersion = System.getProperty("java.specification.version");
181
182 switch (specVersion) {
183 case "10":
184 return RELEASE_10;
185 case "9":
186 case "1.9":
187 return RELEASE_9;
188 case "1.8":
189 return RELEASE_8;
190 case "1.7":
191 return RELEASE_7;
192 case "1.6":
193 return RELEASE_6;
194 }
195 } catch (SecurityException se) {}
196
197 return RELEASE_5;
198 }
199
200 /**
201 * Returns the latest source version fully supported by the
202 * current execution environment. {@code RELEASE_5} or later must
203 * be returned.
204 *
|