RFR: 8277090 : jsr166 refresh for jdk19 [v2]

Rémi Forax forax at openjdk.java.net
Tue May 3 07:19:13 UTC 2022


On Mon, 2 May 2022 23:54:33 GMT, Doug Lea <dl at openjdk.org> wrote:

>> src/java.base/share/classes/java/util/concurrent/FutureTask.java line 222:
>> 
>>> 220:                 throw new IllegalStateException("Task has not completed");
>>> 221:         }
>>> 222:     }
>> 
>> I think the code will be more readable if a switch expression and the arrow syntax are used
>> 
>> 
>> return switch(state()) {
>>     case SUCCESS -> {
>>         @SuppressWarnings("unchecked")
>>         V result = (V) outcome;
>>         yield result;
>>     } 
>>     case FAILED -> throw new IllegalStateException("Task completed with exception");
>>     ...
>> };
>
> Sorry, I don't understand how it would be more readable. I like new switch features because they extend the range of applicability of switch. But this (and the two others) are just plain vanilla enum-based switches that were handled well, and seem to have the same numbers of lines and structure either way?

It's more readable because it's now clear that the aim is to return the value of the switch.
Also a switch expression has to be exhaustive, so there is no need for a 'default'.

-------------

PR: https://git.openjdk.java.net/jdk/pull/8490


More information about the core-libs-dev mailing list