您可以在Java的switch
语句中包含多个变量吗?
enum Facing { North, South, East, West }
enum Forward { Right, Left }
Forward forward;
Facing facing;
Integer myNumber;
看起来像这样吗?如果是这样,我将如何实施
switch (facing, forward) {
case North, Right : facing 1 = East
}
我知道这是错误的,但想知道这种技术是否可行,我将如何实施?
最佳答案
您可以这样:
switch(facing)
{
case North:
switch(forward)
{
case Right: // blah blah
break;
}
break;
}