Edit: No one offered much hope, so here's a link to the SIP for @static members. It's already implemented for Dotty/Scala 3.
However, the members are defined on the companion. The RHS of member definitions can contain arbitrary code, so there's no need for syntax for static initializers as such.
Still wondering what's the use case.
What is your use case?
Ordinarily:
scala 2.13.0-M4> object X { println("hi") }
defined object X
scala 2.13.0-M4> X
hi
res0: X.type = X$@554c4eaa
scala 2.13.0-M4> :javap -c X
Compiled from "<console>"
public class $line3.$read$$iw$$iw$X$ {
public static $line3.$read$$iw$$iw$X$ MODULE$;
public static {};
Code:
0: new #2 // class $line3/$read$$iw$$iw$X$
3: invokespecial #20 // Method "<init>":()V
6: return
public $line3.$read$$iw$$iw$X$();
Code:
0: aload_0
1: invokespecial #21 // Method java/lang/Object."<init>":()V
4: aload_0
5: putstatic #23 // Field MODULE$:L$line3/$read$$iw$$iw$X$;
8: getstatic #28 // Field scala/Predef$.MODULE$:Lscala/Predef$;
11: ldc #30 // String hi
13: invokevirtual #34 // Method scala/Predef$.println:(Ljava/lang/Object;)V
16: return
}
To convince you that this is ordinary static loading:
scala 2.13.0-M4> :pa -raw
// Entering paste mode (ctrl-D to finish)
package y { object Y { println("hi") } }
// Exiting paste mode, now interpreting.
scala 2.13.0-M4> Class.forName
def forName(x$1: String,x$2: Boolean,x$3: ClassLoader): Class[_] def forName(x$1: String): Class[_]
scala 2.13.0-M4> Class.forName("y.Y$", true, getClass.getClassLoader)
hi
res5: Class[_] = class y.Y$