Why would I use a static block:
static {
B = 10;
}
over:
Integer B = 10;
What is the advantages/disadv
First your Integer B
appears to be a non static member variable and can not be accessed from a static block. So you either meant to write
//Initialize static field
static {
B = 10;
}
static Integer B = 10;
or
//Initialize member field
{
B = 10;
}
Integer B = 10;
In both cases you can use it to initialize B with a value that could cause an exception or do something more complex without writing a special method for init.
{
try{
B = thisWillThrowAFileNotFound();
}catch(FileNotFoundException){
B = 10;//Set default
}
}