Ioanna Katsanou wrote:
I cannot understand why in the first case it does not compile. Shouldn'it it throw an exception in initializer error like the second example?
Section 8.7 of the JLS requires that static initializers can complete normally. The first case does not, and hence, fails to compile.
Section 14.21 of the JLS are the tests to determine whether code is reachable. This is also the test for completing normally.... and there are special cases for the if/then to allow for conditional code. Hence, it is possible for the if/then to complete normally, hence, the second case compiles.