+ 1

Static Block / Static Initializer

I recently encountered this idea doing challenges in Java. I understand that static initializers are used to initialize variables and that they run before anything else. I don't understand why they are used as opposed to just initializing at the beginning of your program in the main method. I'm hoping someone can shed some light on this topic for me! I'm asking about Java but I'm sure this same idea is used across many languages and can be applied in the same way. If so, feel free to elaborate. Thanks!

2nd Apr 2018, 6:30 PM
Justin Hinkle
Justin Hinkle - avatar
2 Antworten
+ 11
Contains helpful information about the initialization process of the jvm. More and better I could provide it, so pls refer: https://stackoverflow.com/questions/9056895/why-use-static-blocks-over-initializing-instance-variables-directly
2nd Apr 2018, 8:52 PM
Tashi N
Tashi N - avatar
+ 1
Helpful thread, thanks Tashi!
2nd Apr 2018, 9:47 PM
Justin Hinkle
Justin Hinkle - avatar