需要在初始时对final型的a赋值
public class test{ static final int a; static{
a=methed();
}}问题是这个method需要一个error handle,
但是如果我用
static{
try{
a=methed();
}catch(Exception e){}
}
的话,a就无法在初始时赋值了,请问怎么处理?
public class test{ static final int a; static{
a=methed();
}}问题是这个method需要一个error handle,
但是如果我用
static{
try{
a=methed();
}catch(Exception e){}
}
的话,a就无法在初始时赋值了,请问怎么处理?
{
static final int a;
static int b;
static
{
try
{
b = methed();
}
catch (Exception e)
{
//your codes here
}
finally
{
a = b;
}
} static int methed()
{
return 1;
}
}