Call for feedback -- enhanced switch

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Sat Mar 23 21:27:47 UTC 2019


On 23/03/2019 17:38, Remi Forax wrote:
> And the expression switch is supported by the latest releases of both IntelliJ IDEA and Eclipse [1]
>
> BTW, it remember me something i have forgotten to ask, for both ecj and javac, when you compile with --enable-preview, all the classes have they minor version changed even the one that doesn't use the switch expression. I've tried to find where this behaviour was documented in the JEP 12 [2] but the "compile-time" section is not clear about that.

Remi, my initial implementation of JEP 12 was actually doing the finer 
grained treatment you described.

But it was suggested in the review comments that it was too much, and 
the logic was reverted to a more predictable all-on/all-off switch.

>
> Also, the section talk about being able to suppress the preview warning when referencing an entity like a record from another class, but it's not clear if the warning emitted because the switch expression is used in the current class can be suppressed or not, the JEP draws a parallel with @Deprecated so i suppose the answer is yes, in that case javac has to be updated because as far as i know @SuppressWarnings("preview") doesn't work (it works with ecj).

Right now, suppressible warnings in JEP 12 only apply to preview 
declaration features (e.g. records), not to statement features.

The default behavior javac has is to disable preview warnings by default 
- but generate a mandatory message if any preview feature was used, 
either directly or indirectly, as per JEP 12.

So, if the user wanted more detailed info about uses of preview 
features, the -Xlint:preview flag can be used. Javac does not treat 
these warnings as suppressible at the moment. The risk is that if you do 
-Xint:preview and allgard your warnings have been suppressed with 
annotations, you will get no message from javac regarding the use of 
preview features at all.

Of course the implementation can change if we feel that warnings related 
to usage of preview features should be suppressible too (individually, I 
mean). I don't see a lot of value in that, though.

Maurizio


>
> regards,
> Rémi
>
> [1] for Eclipse you have to install a patch: https://www.youtube.com/watch?v=TPtXIal9APw
> [2] https://openjdk.java.net/jeps/12
>
> ----- Mail original -----
>> De: "Brian Goetz" <brian.goetz at oracle.com>
>> À: "amber-dev" <amber-dev at openjdk.java.net>
>> Envoyé: Samedi 23 Mars 2019 17:21:03
>> Objet: Re: Call for feedback -- enhanced switch
>> Reminder, now that Java 12 is officially out ...
>>
>> On 3/1/2019 4:55 PM, Brian Goetz wrote:
>>> We would like to promote enhanced switch to a permanent feature in Java 13.  So
>>> far, the only change we are anticipating is:
>>>
>>>       - change “break value” to “break-with value”.
>>>
>>> This is the time for people to try it out on their codebases (there’s even
>>> refactoring support in IDEA!) and provide feedback on what works, what doesn’t,
>>> and what was surprising.
>>>


More information about the amber-dev mailing list