Files
javademos/docs/output/81-scoped-values.txt

42 lines
1.9 KiB
Plaintext

# ScopedValue (JEP 506). Preview API in 21, final in 25.
$ javac ScopedValueDemo.java (JDK 21, no flag)
<repo>/lanes/src/ScopedValueDemo.java:9: error: ScopedValue is a preview API and is disabled by default.
static final ScopedValue<String> CURRENT_USER = ScopedValue.newInstance();
^
(use --enable-preview to enable preview APIs)
<repo>/lanes/src/ScopedValueDemo.java:9: error: ScopedValue is a preview API and is disabled by default.
static final ScopedValue<String> CURRENT_USER = ScopedValue.newInstance();
^
(use --enable-preview to enable preview APIs)
<repo>/lanes/src/ScopedValueDemo.java:13: error: ScopedValue is a preview API and is disabled by default.
ScopedValue.where(CURRENT_USER, "ankur").run(() -> {
^
(use --enable-preview to enable preview APIs)
3 errors
exit=1
$ javac ScopedValueDemo.java (JDK 25, no flag)
exit=0
$ java ScopedValueDemo (JDK 25)
java.version = 25.0.4.1
CHECK ok : inside the scope: CURRENT_USER.get() == ankur
CHECK ok : a method that was never passed the value still sees it
CHECK ok : outside the scope: CURRENT_USER.get() throws NoSuchElementException
$ javac ScopedValueDemo.java (JDK 26, no flag)
exit=0
$ java ScopedValueDemo (JDK 26)
java.version = 26.0.2.1
CHECK ok : inside the scope: CURRENT_USER.get() == ankur
CHECK ok : a method that was never passed the value still sees it
CHECK ok : outside the scope: CURRENT_USER.get() throws NoSuchElementException
$ javac ScopedValueDemo.java (JDK 27, no flag)
exit=0
$ java ScopedValueDemo (JDK 27)
java.version = 27
CHECK ok : inside the scope: CURRENT_USER.get() == ankur
CHECK ok : a method that was never passed the value still sees it
CHECK ok : outside the scope: CURRENT_USER.get() throws NoSuchElementException