Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dealing with null with switch expression #100

Open
Just-some-one opened this issue May 26, 2024 · 0 comments
Open

dealing with null with switch expression #100

Just-some-one opened this issue May 26, 2024 · 0 comments

Comments

@Just-some-one
Copy link

Hello

for dealing with null section on the switch expression

it should be update to reflect that it's not preview feature now to deal with null using switch expression

maybe an example with little modification to that code that presented in same page under switch-syntax section

int day = ...; // any day
int len =
    switch (day) {
        case MONDAY, FRIDAY, SUNDAY -> 6;
        case TUESDAY                -> 7;
        case THURSDAY, SATURDAY     -> 8;
        case WEDNESDAY              -> 9;
    }
System.out.println("len = " + len);

to be

Day day = null;
int len = switch (day) {

            case MONDAY, FRIDAY, SUNDAY -> 6;
            case TUESDAY                -> 7;
            case THURSDAY, SATURDAY     -> 8;
            case WEDNESDAY              -> 9;
            case null -> -1;

        };
 
System.out.println("len = " + len);

thanks for your time and have a nice day :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant