JEP proposed to target JDK 12: 325: Switch Expressions (Preview)
Robert Zenz
robert.zenz at sibvisions.com
Thu Aug 23 13:39:33 UTC 2018
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