I noticed something in static initializers, which may be a bug in javac. I built a script where I can assign a variable a value but not read that value.
Two examples are given below: the first is compiled, the second gets an error when trying to read the value from tmp, but for some reason the assignment of the tmp value is allowed. I could understand if he couldn’t read or write the variable, since tmp is declared after the static initializer, but the error only for one of them does not make sense to me.
to emphasize this point, it compiles successfully.
public class Script { static { tmp = new Object(); } public static Object tmp; }
source share