static initialization in interface

Interfaces should not have side-effects and that even applies to static intializers. They would have highly JVM-implementation dependent behavior. Look at the following code public class InterfaceSideEffects { public static void main(String[] args) { System.out.println(“InterfaceSideEffects.main()”); Impl i=new Impl(); System.out.println(“Impl initialized”); i.bla(); System.out.println(“Impl instance method invoked”); Foo f=new Impl(); System.out.println(“Impl initialized and assigned to Foo”); f.bla(); … Read more

Why isn’t a qualified static final variable allowed in a static initialization block?

The JLS holds the answer (note the bold statement): Similarly, every blank final variable must be assigned at most once; it must be definitely unassigned when an assignment to it occurs. Such an assignment is defined to occur if and only if either the simple name of the variable (or, for a field, its simple … Read more

Is final ill-defined?

A very interesting find. To understand it we need to dig into the Java Language Specification (JLS). The reason is that final only allows one assignment. The default value, however, is no assignment. In fact, every such variable (class variable, instance variable, array component) points to its default value from the beginning, before assignments. The … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)