JEP proposed to target JDK 12: 325: Switch Expressions (Preview)

Robert Zenz robert.zenz at sibvisions.com
Fri Aug 24 07:48:59 UTC 2018


I see, thank you.


On 23.08.2018 16:11, Stephen Colebourne wrote:
> Null handling was deferred. I believe this is the current spec
> http://cr.openjdk.java.net/~gbierman/switch-expressions.html
> 
> (I support the rationale for deferring nulls, see amber-dev/amber-spec-experts)
> 
> Stephen
> 
> On 23 August 2018 at 14:39, Robert Zenz <robert.zenz at sibvisions.com> wrote:
>> Wasn't one of the original complaints about the `switch` statement its `null`
>> behavior? I'm not seeing that addressed in the JEP, neither for the statement
>> nor for the expression.
>>
>> I mean, the following fails with a `NullPointerException`:
>>
>>     MyEnum value = null;
>>
>>     switch(value) {
>>         case MyEnum.A:
>>             // Do something
>>             break;
>>     }
>>
>> I'm not seeing outlined in the JEP how the expression would react to that:
>>
>>     MyEnum value = null;
>>
>>     int result = switch(value) {
>>         case MyEnum.A -> 5;
>>     }
>>
>> Also, while we are at that topic, I could not find a JEP for actually fixing the
>> `switch` statement behavior to correctly handle `null`. Has somebody seen one?
>>
>> As an idea for that, something like this should preserve backwards compatibility:
>>
>>     MyEnum value = null;
>>
>>     // Fails with a NullPointerException
>>     switch(value) {
>>         case MyEnum.A:
>>             // Do something
>>             break;
>>     }
>>
>>     // Succeeds
>>     switch(value) {
>>         case MyEnum.A:
>>             // Do something
>>             break;
>>
>>         case null:
>>             // Do something else.
>>             break;
>>     }
>>
>> If I'm not mistaken, that is.
>>
>>
>> On 17.08.2018 19:44, mark.reinhold at oracle.com wrote:
>>> The following JEP is proposed to target JDK 12:
>>>
>>>   325: Switch Expressions (Preview)
>>>        http://openjdk.java.net/jeps/325
>>>
>>> Feedback on this proposal is more than welcome, as are reasoned
>>> objections.  If no such objections are raised by 23:00 UTC on Friday,
>>> 24 August, or if they’re raised and then satisfactorily answered, then
>>> per the JEP 2.0 process proposal [1] I’ll target this JEP to JDK 12.
>>>
>>> - Mark
>>>
>>>
>>> [1] http://cr.openjdk.java.net/~mr/jep/jep-2.0-02.html
>>>


More information about the jdk-dev mailing list