Can we call “case” in another case in the same switch statement of Java?
•
Java
My intention is to call two case in another case in the same switch statement.
switch (orderType) {
case 1:
statement 1;
break;
case 2:
statement 2;
break;
case 3:
**call case 1;**
**Call case 2;**
break;
default:
break;`
}
Can we do it in Java?
Solution
Although you can't directly affect the handover case, you can invoke the parent method of switch from a case and pass different parameters. For example,
void foo(int param1,String param2,...) {
switch (param1) {
case 0:
foo(1,"some string");
break;
case 1:
//do something
break;
default:
break;
}
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
