Skip to content

Instantly share code, notes, and snippets.

@vaskoz
Last active August 3, 2019 21:20
Show Gist options
  • Save vaskoz/0943338afa25a87751fa40ecc3711f10 to your computer and use it in GitHub Desktop.
Save vaskoz/0943338afa25a87751fa40ecc3711f10 to your computer and use it in GitHub Desktop.
[tmp] java -version
openjdk version "13-ea" 2019-09-17
OpenJDK Runtime Environment (build 13-ea+32)
OpenJDK 64-Bit Server VM (build 13-ea+32, mixed mode, sharing)
[tmp] java --enable-preview --source 13 Switch.java Foo
Note: Switch.java uses preview language features.
Note: Recompile with -Xlint:preview for details.
The quick brown fox
jumps over the lazy dog
1
[tmp] java --enable-preview --source 13 Switch.java Bar
Note: Switch.java uses preview language features.
Note: Recompile with -Xlint:preview for details.
The quick brown fox
jumps over the lazy dog
2
[tmp] java --enable-preview --source 13 Switch.java Other
Note: Switch.java uses preview language features.
Note: Recompile with -Xlint:preview for details.
The quick brown fox
jumps over the lazy dog
0
[tmp] java --enable-preview --source 13 Switch.java 1223
Note: Switch.java uses preview language features.
Note: Recompile with -Xlint:preview for details.
The quick brown fox
jumps over the lazy dog
0
public class Switch {
public static void main(String... args) {
var s = args[0];
int result = switch (s) {
case "Foo" -> 1;
case "Bar" -> 2;
default -> 0;
};
String msg2 = """
The quick brown fox\040\040
jumps over the lazy dog
""";
System.out.println(msg2 + result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment