You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Daniel Sun (Jira)" <ji...@apache.org> on 2021/07/24 09:35:00 UTC
[jira] [Commented] (GROOVY-9272) Support switch expression
[ https://issues.apache.org/jira/browse/GROOVY-9272?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17386683#comment-17386683 ]
Daniel Sun commented on GROOVY-9272:
------------------------------------
{code:java}
int eval(Expr n) {
return switch(n) {
case IntExpr(int i) -> i;
case NegExpr(Expr n) -> -eval(n);
case AddExpr(Expr left, Expr right) -> eval(left) + eval(right);
case MulExpr(Expr left, Expr right) -> eval(left) * eval(right);
default -> throw new IllegalStateException();
};
}
{code}
[~paulk]
Destructuring is supported now:
https://github.com/apache/groovy/commit/8424d3a1258059587f955ccd5f771a4aa2ca5db2
> Support switch expression
> -------------------------
>
> Key: GROOVY-9272
> URL: https://issues.apache.org/jira/browse/GROOVY-9272
> Project: Groovy
> Issue Type: New Feature
> Reporter: Daniel Sun
> Assignee: Daniel Sun
> Priority: Major
> Fix For: 4.0.0-beta-1
>
> Time Spent: 1.5h
> Remaining Estimate: 0h
>
> See JEP 361( [https://openjdk.java.net/jeps/361] )
>
> The following references are a bit outdated:
> JEP 354( [https://openjdk.java.net/jeps/354] )
> JEP 325( [https://openjdk.java.net/jeps/325] )
> [https://blog.codefx.org/java/switch-expressions/]
> [https://dzone.com/articles/jdk-12-switch-statementsexpressions-in-action]
> [https://blog.idrsolutions.com/2019/03/java-12-switch-expressions-explained-in-5-minutes/]
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)