Switch expression with string concatenation (original) (raw)
Tagir Valeev amaembo at gmail.com
Tue Nov 20 09:40:28 UTC 2018
- Previous message: spec clarification: type annotations on static nested types
- Next message: Switch expression with string concatenation
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hello!
Seems that switch expression behaves badly with string concatenation. Example:
public class Java12Test { public static void main(String[] args) { String s = "foo"; System.out.println(s + switch(0) { default -> { s = "bar"; break 1; } }); System.out.println(s); } }
"C:\Program Files\Java\jdk-12\bin\java.exe" -version openjdk version "12-ea" 2019-03-19 OpenJDK Runtime Environment (build 12-ea+20) OpenJDK 64-Bit Server VM (build 12-ea+20, mixed mode, sharing)
"C:\Program Files\Java\jdk-12\bin\javac.exe" --enable-preview --release=12 Java12Test.java Note: Java12Test.java uses preview language features. Note: Recompile with -Xlint:preview for details.
"C:\Program Files\Java\jdk-12\bin\java.exe" --enable-preview Java12Test foo1 foo
As you can see, s = "bar"
assignment was not executed.
With best regards, Tagir Valeev
- Previous message: spec clarification: type annotations on static nested types
- Next message: Switch expression with string concatenation
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]