[ 
https://issues.apache.org/jira/browse/JEXL-440?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Henri Biestro updated JEXL-440:
-------------------------------
    Description: 
switch / case / default basic behavior; statement and expression
Switch as a statement follows Java rules; case values must be constant (null 
and NaN are allowed though), return is allowed, no default clause is never an 
issue.
Switch as expression essentially mimick Java rules with the same constant rules 
as the statement, return is not allowed. No strong typing means JEXL can not 
verify completeness of case matching at parsing tyime; a lack of default clause 
triggers a runtime exception if no case matched.

The differences between statement & expressions in a nutshell:
Statement:
{code:java}
switch (s) {
case 1: {
// some code
break;
}
case 2:
// more code, follow through to 3
case 3:
return 5; // return is allowed
}
{code}
Expression:

{code:java}
let v = switch (s) {
case 1 -> 10; 
case 2, 3 -> 20;
case 4 -> { 30 + 10 } // jexl is functional, no yield needed
default -> null // if not present and no case match, error
}
{code}


  was:
switch / case / default basic behavior; statement and expression

The differences between statement & expressions:
Syntax:
Statement:
{code:java}
switch (s) {
case 1: {
// some code
break;
}
case 2:
// more code, follow through to 3
case 3:
return 5; // return is allowed
}
{code}
Expression:

{code:java}
let v = switch (s) {
case 1 -> 10; 
case 2, 3 -> 20;
case 4 -> { 30 + 10 } // jexl is functional, no yield needed
default -> null // if not present and no case match, error
}
{code}



> Switch statement & expressions
> ------------------------------
>
>                 Key: JEXL-440
>                 URL: https://issues.apache.org/jira/browse/JEXL-440
>             Project: Commons JEXL
>          Issue Type: New Feature
>    Affects Versions: 3.5.0
>            Reporter: Henri Biestro
>            Assignee: Henri Biestro
>            Priority: Major
>             Fix For: Later
>
>
> switch / case / default basic behavior; statement and expression
> Switch as a statement follows Java rules; case values must be constant (null 
> and NaN are allowed though), return is allowed, no default clause is never an 
> issue.
> Switch as expression essentially mimick Java rules with the same constant 
> rules as the statement, return is not allowed. No strong typing means JEXL 
> can not verify completeness of case matching at parsing tyime; a lack of 
> default clause triggers a runtime exception if no case matched.
> The differences between statement & expressions in a nutshell:
> Statement:
> {code:java}
> switch (s) {
> case 1: {
> // some code
> break;
> }
> case 2:
> // more code, follow through to 3
> case 3:
> return 5; // return is allowed
> }
> {code}
> Expression:
> {code:java}
> let v = switch (s) {
> case 1 -> 10; 
> case 2, 3 -> 20;
> case 4 -> { 30 + 10 } // jexl is functional, no yield needed
> default -> null // if not present and no case match, error
> }
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to