为什么这是编译错误?Java 无法同时达到bar
.
import java.util.Random;
public class SwitchTest {
public static void main(String[] args) {
Random r = new Random();
int foo = r.nextInt(2);
switch(foo) {
case 0:
int bar = r.nextInt(10);
System.out.println(bar);
break;
case 1:
int bar = r.nextInt(10) + 10; // Doesn't compile!!
System.out.println(bar);
break;
}
}
}