Assertions in static blocks ?

David Holmes - Sun Microsystems David.Holmes at Sun.COM
Sun Mar 7 14:20:32 PST 2010


Ulf Zibis said the following on 03/08/10 01:40:
> In contrast to Keith and Neal, I think, we agree, that this "behaviour 
> is surprising", so I would vote at least for a *warning* from javac side.

I'm with Keith and Neal, this is all "working as designed". How can 
javac in general know whether or not a class will be initialized. A 
static initializer is no different to a method or constructor in that 
regard: none of them are ever flagged as unreachable because that can't 
be determined a-priori by javac.

At the absolute most I can concede that javac might issue a warning if a 
class consisted only of constant field declarations and had a static 
initializer, as no use of the fields would lead to initialization. But 
even then I don't think this is worth the effort.

Regards,
David Holmes



More information about the compiler-dev mailing list