import java.util.Random;
public class Holder{
public static void f(boolean b) throws Exception{
System.out.println("Kobe");
if(b)
throw new Exception("Error from f()");
}
public static void main(String[] args) throws Throwable{
try{
Random rand=new Random();
int a=rand.nextInt(2);
boolean c;//我这里没有初始化,但下面根据来初
//始化了,但是却不能被编译,说是c没
//有被初始化,这是怎么回事?
switch(a){
case 0:
c=true;
break;
case 1:
c=false;
break;
default:
System.out.print("Bryant");
}
f(c);
}catch(Exception e){
System.err.println("f() Error!");
e.printStackTrace();
}
}
}
public class Holder{
public static void f(boolean b) throws Exception{
System.out.println("Kobe");
if(b)
throw new Exception("Error from f()");
}
public static void main(String[] args) throws Throwable{
try{
Random rand=new Random();
int a=rand.nextInt(2);
boolean c;//我这里没有初始化,但下面根据来初
//始化了,但是却不能被编译,说是c没
//有被初始化,这是怎么回事?
switch(a){
case 0:
c=true;
break;
case 1:
c=false;
break;
default:
System.out.print("Bryant");
}
f(c);
}catch(Exception e){
System.err.println("f() Error!");
e.printStackTrace();
}
}
}
你直接给c一个true或者false的初始值就好