Based on my understanding of the Java language, static variables can be initialized in
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes of course:
static finalvariables can be initialized in a static block but…. you have implicit GOTOs in that example (try/catchis essentially a ‘GOTO catch if something bad happens’).If an exception is thrown your
finalvariables 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.