When I tried to write something like this:
public interface MyInterface {
    static {
        System.out.println("Hello!");
    }
}
the compiler could not compile it.
But when I wrote something like this:
interface MyInterface {
    Integer iconst = Integer.valueOf(1);
}
and decompiled it, I saw static initialization:
public interface MyInterface{
    public static final java.lang.Integer i;
    static {};
      Code:
      0:   iconst_1
      1:   invokestatic    #1; //Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      4:   putstatic       #2; //Field i:Ljava/lang/Integer;
      7:   return
}
Could you please explain this behavior to me?
 
     
     
     
     
    