Call for feedback -- switch expressions in JDK 12

Manoj Palat manoj.palat at in.ibm.com
Wed Apr 17 23:50:34 UTC 2019


Hi Alex,
Please find our feedback from Eclipse Java Dev.

   1)	For the break expression part we would be happy to have the
      “overloading” of break replaced by something else ? since this is
      already in the cards, no additional comment on this part.

   2)	Thanks to Remi Forax raising a bug in ecj [
      https://bugs.eclipse.org/bugs/show_bug.cgi?id=545716] and the
      following discussions, we believe that there could be a bug [in spec,
      javac as well as ecj] ? see this comment from Stephan Herrmann
      https://bugs.eclipse.org/bugs/show_bug.cgi?id=545716#c16 specifically
      for the findings. [@Alex: I am taking the liberty of pointing to the
      bug link rather than summarizing here since you have mentioned that a
      blog pointer should also be fine]

   Regards,

   Manoj

   Eclipse Java Dev, IBM




From:	Alex Buckley <alex.buckley at oracle.com>
To:	jdk-dev at openjdk.java.net
Date:	04/17/2019 11:23 PM
Subject:	Re: Call for feedback -- switch expressions in JDK 12
Sent by:	"jdk-dev" <jdk-dev-bounces at openjdk.java.net>



The feedback we're looking for is "I tried switch expressions in my code
and observed ...". For example:

https://urldefense.proofpoint.com/v2/url?u=https-3A__mail.openjdk.java.net_pipermail_amber-2Ddev_2019-2DMarch_004199.html&d=DwIFaQ&c=jf_iaSHvJObTbx-siA1ZOg&r=A51zLdywEjS50U7u2UMWvsDIrUGEJ5IDXskL5MxIEjA&m=yINx0-noxNSSsm-dLx2P9YD7dvF6187FW7CStT07mp4&s=9at0fZB0bQpeEPI5L2IWbMSlUqcdgEsfF5944Rfjaxo&e=


If anyone is blogging about their experience with switch expressions,
feel free to share the URL here. For example, here's a great writeup of
using switch expressions in lambdas:

https://urldefense.proofpoint.com/v2/url?u=http-3A__minborgsjavapot.blogspot.com_2019_03_java-2D12-2Dmapping-2Dwith-2Dswitch-2Dexpressions.html&d=DwIFaQ&c=jf_iaSHvJObTbx-siA1ZOg&r=A51zLdywEjS50U7u2UMWvsDIrUGEJ5IDXskL5MxIEjA&m=yINx0-noxNSSsm-dLx2P9YD7dvF6187FW7CStT07mp4&s=JE0ESlf3gLQJ5-QzuOU1uR_xMLngiysxuz0o948ZlW4&e=


Alex

On 4/16/2019 8:24 PM, Netroby wrote:
>     int numLetters = switch (day) {
>         case MONDAY, FRIDAY, SUNDAY -> 6,
>         case TUESDAY                -> 7,
>         case THURSDAY, SATURDAY     -> 8,
>         case WEDNESDAY              -> 9,
>         _ -> 0,
>     };
>
> Should we using  comma , instead of ;
>
> comma , means these cases the same switch.
>
> Another point, should we have an default match pattern ? using _ or
default
>
>
> idea from rust match
> ```rust
> fn main() {
>      let number = 13;
>      // TODO ^ Try different values for `number`
>
>      println!("Tell me about {}", number);
>      match number {
>          // Match a single value
>          1 => println!("One!"),
>          // Match several values
>          2 | 3 | 5 | 7 | 11 => println!("This is a prime"),
>          // Match an inclusive range
>          13...19 => println!("A teen"),
>          // Handle the rest of cases
>          _ => println!("Ain't special"),
>      }
>
>      let boolean = true;
>      // Match is an expression too
>      let binary = match boolean {
>          // The arms of a match must cover all the possible values
>          false => 0,
>          true => 1,
>          // TODO ^ Try commenting out one of these arms
>      };
>
>      println!("{} -> {}", boolean, binary);
> }
>
> ```
>
> Appreciate your time.
> ----------------------------
> Netroby
>
> Alex Buckley <alex.buckley at oracle.com> 于2019年4月17日周三 上午10:00写
道:
>>
>> An easy way to help move Java forward is to try out new features on real
>> code and share your experiences. We're asking for feedback on how you
>> use switch expressions, the new language feature in JDK 12:
>>
>>     int numLetters = switch (day) {
>>         case MONDAY, FRIDAY, SUNDAY -> 6;
>>         case TUESDAY                -> 7;
>>         case THURSDAY, SATURDAY     -> 8;
>>         case WEDNESDAY              -> 9;
>>     };
>>
>>     // Multiple labels per case (also allowed in switch statements)
>>     // No fallthrough with the -> form (also allowed in switch
statements)
>>
>> Do you find switch expressions useful? Is anything surprising? Did you
>> turn any switch statements into switch expressions? Please let us know
>> on this list, even if the answer is "Tried it. Works fine."
>>
>> To enable switch expressions in your environment:
>> - IntelliJ IDEA 2019.1
>>
https://urldefense.proofpoint.com/v2/url?u=https-3A__blog.jetbrains.com_idea_2019_02_java-2D12-2Dand-2Dintellij-2Didea_&d=DwIFaQ&c=jf_iaSHvJObTbx-siA1ZOg&r=A51zLdywEjS50U7u2UMWvsDIrUGEJ5IDXskL5MxIEjA&m=yINx0-noxNSSsm-dLx2P9YD7dvF6187FW7CStT07mp4&s=-WsqDARpX60gLIBem_6IqycbQFRWL5bzkTNGVV322aU&e=

>> - Eclipse 4.11
https://urldefense.proofpoint.com/v2/url?u=https-3A__www.eclipse.org_eclipse_news_4.11_jdt.php-23Java12&d=DwIFaQ&c=jf_iaSHvJObTbx-siA1ZOg&r=A51zLdywEjS50U7u2UMWvsDIrUGEJ5IDXskL5MxIEjA&m=yINx0-noxNSSsm-dLx2P9YD7dvF6187FW7CStT07mp4&s=zClnCpCg04gt1vZS1Zz8j64uam6ZkpnGMVe4M5kCYd0&e=

>> - Apache NetBeans 11.0
>>
https://urldefense.proofpoint.com/v2/url?u=https-3A__cwiki.apache.org_confluence_pages_viewpage.action-3FpageId-3D103091452&d=DwIFaQ&c=jf_iaSHvJObTbx-siA1ZOg&r=A51zLdywEjS50U7u2UMWvsDIrUGEJ5IDXskL5MxIEjA&m=yINx0-noxNSSsm-dLx2P9YD7dvF6187FW7CStT07mp4&s=5RLv6qs5qiU3r9dJ8KjnT4aPKRyz8hxXvNN0w5Z6x94&e=

>> - jshell in JDK 12  run with `--enable-preview`
>> - javac in JDK 12  run with `--release 12 --enable-preview`
>>
>> Alex





More information about the jdk-dev mailing list