Java – Can final variables be initialized in static initialization block?

Yes of course: static final variables can be initialized in a static block but…. you have implicit GOTOs in that example (try/catch is essentially a ‘GOTO catch if something bad happens’).

If an exception is thrown your final variables will not be initialized.

Note that the use of static constructs goes against Object-Oriented dogma. It may complicate your testing and make debugging more difficult.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)