Difference between static modifier and static block [duplicate]
This question already has an answer here: What is the difference between a static and a non-static initialization code block 8 answers Someone explain to me the differences between the following two statements? A static final variable initialized by a static code block: private static final String foo; static { foo = "foo"; } A static final variable initialized by an assignment: private static final String foo = "foo"; In this example, there's one subtle difference - in your first example, foo isn't determined to be a compile-time constant, so it can't be used as a case in switch blocks (and