We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
What's missing from all these explanations is they all focus on "how it works" and not "why you would want to do it" which remains still partiallly a mystery to me. Apart from allowing one to run commands out of sequence - and why would you want to do that? - the best explanation of what it's for that I could find is...
"The advantage of private static methods is that they can be reused later if you need to reinitialize the class variable. So, you kind of get more flexibility with a private static method in comparison to the corresponding static initialization block. This should not mislead that a 'public' static method can't do the same. But, we are talking about a way of initializing a class variable and there is hardly any reason to make such a method 'public'. "
Java Static Initializer Block
You are viewing a single comment's thread. Return to all comments →
What's missing from all these explanations is they all focus on "how it works" and not "why you would want to do it" which remains still partiallly a mystery to me. Apart from allowing one to run commands out of sequence - and why would you want to do that? - the best explanation of what it's for that I could find is...
"The advantage of private static methods is that they can be reused later if you need to reinitialize the class variable. So, you kind of get more flexibility with a private static method in comparison to the corresponding static initialization block. This should not mislead that a 'public' static method can't do the same. But, we are talking about a way of initializing a class variable and there is hardly any reason to make such a method 'public'. "
http://www.jusfortechies.com/java/core-java/static-blocks.php