[Java Silver] Things to be aware of regarding switch statements

Grammatic structure of switch statement

switch(variable){
case condition: //processing;
               break;
case condition: //processing;
               break;
     default:  //processing;
               break;
}

-Although the default label is customarily written at the very end, ** There is no problem if you write something other than the last **

・ If you forget to write the break statement **, you will proceed to the processing of the next condition ** (fallthrough)

What can be written in the case value

·constant **-The same type as or compatible with the variable type described in the conditional expression **

Things that cannot be written in the case value

·variable **-Types that are incompatible with the variable types described in the conditional expression ** ** ・ null ** ** ・ Long type ** ** ・ Boolean type **

Recommended Posts

[Java Silver] Things to be aware of regarding switch statements
Things to be aware of when writing Java
[Java] Things to be aware of when outputting FizzBuzz
Things to be aware of when writing code in Java
Things to be aware of when using devise's lockable
To be aware of easy-to-read code
5 things new programmers should be aware of
Java Servlet should be aware of multithreaded environment
[Beginner] Points to be aware of after Java exercises / Inheritance / Abstract method [Note 26]
[Java] [Microsoft] Things to be aware of when including the JDBC driver for SQL Server in one jar
[Java Silver] Summary of points related to lambda expressions
I want to be aware of the contents of variables!
Java conditional branching: How to create and study switch statements
[Java] Summary of for statements
Be sure to compare the result of Java compareTo with 0
Evolutions of enums and switch statements! ?? Try to achieve algebraic data types and pattern matching in Java
How to study Java Silver SE 8
Summary of [Java silver study] package
Road to Java SE 11 Silver acquisition
[Java] Input to stdin of Process
Java to be involved from today
How to pass Oracle Java Silver
Practice of Java programming basics-I want to display triangles with for statements ①
Practice of Java programming basics-I want to display triangles with for statements ②
[Java Silver] Summary of access modifier points
[java] Summary of how to handle char
Java SE8 Silver ~ The Road to Pass ~
How to use submit method (Java Silver)
[Java] Personal summary of conditional statements (basic)
How to switch Java versions on Mac
[Java] [Maven3] Summary of how to use Maven3
Inexperienced learning methods to get Java Silver 11
Output of the book "Introduction to Java"
How to switch between multiple Java versions
Basics of java basics ② ~ if statement and switch statement ~