Static Initialization Blocks

As far as I understood the “static initialization block” is used to set values of static field if it cannot be done in one line.

But I do not understand why we need a special block for that. For example we declare a field as static (without a value assignment). And then write several lines of the code which generate and assign a value to the above declared static field.

Why do we need this lines in a special block like: static {...}?

14 Answers
14

Leave a Comment