groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From MG <mg...@arscreat.com>
Subject Re: [GEP] Switch expressions syntax from Java 11 or 12 (perhaps)
Date Thu, 08 Mar 2018 22:55:11 GMT
Hi Remi,

I have used Groovy exclusively for the last years, so not really used to 
Java lambdas, but why can't you use something along the line of:

int result = switch (s) {
     case "Foo" -> 1;
     case "Bar" -> 2;
     case default -> (System.out.println("Neither Foo nor Bar, 
hmmm...");  3; )
}

or

int result = switch (s) {
     case "Foo" -> 1;
     case "Bar" -> 2;
     case PATTERN_ANY -> { System.out.println("Neither Foo nor Bar, 
hmmm...");  3; }
}

etc ?

I am in the "never liked break camp", so I also would not want to see 
its use elevated... ;-)
Cheers,
mg


On 08.03.2018 20:52, Remi Forax wrote:
>
>>> int result = switch (s) {
>>>      case "Foo" -> 1;
>>>      case "Bar" -> 2;
>>>      default:
>>>          System.out.println("Neither Foo nor Bar, hmmm...");
>>>          break 3;
>>> }
>> is straight from the JEP 325 page. And that was actually my point, this
>> overlap, but redefinition of break.
> yes, you can not use the normal break/containue inside an expression,
> so break foo; in an expression switch has only one meaning.
>
>> break is what makes the switch-case ugly for most people in the first place. Giving
that special treatment like this looks off to me.
> using break here is ugly, i agree with you but we (the amber EG) are not able to find
a better solution,
> if you know a better way to handle local return of a value in the case of a switch, please
help us.
>
>


Mime
View raw message