I was wondering, what is there any different, on various ways to initialize static final variable?
private static final int i = 100;
or
private static final int i;
static {
i = 100;
}
Is there any different among the two?
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.
If you’re only setting variables, both forms are equivalent (and you should use the former as it is more readable and succinct).
The
static {}form exists for cases where you also need to execute statements other than variable assignments. (Somewhat contrived) example: