Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Java by (3.9k points)

Integer i = ...

switch (i){

    case null:

        doSomething0();

        break;    

    }

In the code above I cant use null in switch case statement. How can I do this differently? I can't use default because then I want to do something else.

1 Answer

0 votes
by (46k points)

Try: 

switch ((i != null) ? i : DEFAULT_VALUE) {

        //...

}

Related questions

0 votes
1 answer
asked Dec 22, 2020 in SQL by Appu (6.1k points)
+1 vote
2 answers
0 votes
1 answer
0 votes
1 answer

Browse Categories

...