Do we need to enhance @static?


#1

We know that @static was proposed in SIP 25, and it has been implemented in Dotty.
Currently, when an object member is all annotated with @static, the compiler still generates a corresponding class file for it.These objects have no practical use in most cases, and I think we should allow users to somehow prevent the compiler from generating them.For example, we can add new usage for @static:

class Test 

@static
object Test {
  @static
  def f: Int = 100
}

Or we can go one step further. When an object is annotated with @static , all its members are treated as being annotated with @static , which may help us reduce a lot of duplicate work.
Preventing the compiler from generating useless objects can help us reduce the output file size, make Dotty-generated bytecode more controllable, and be more friendly to other JVM languages.


#2

No one is interested in this proposal?
Allowing annotation of objects as @static has the additional advantage of being able to avoid object inheritance from the Any to redundant methods,.


#3

emmm that’s a good idea.


#4

I see value in such a proposal, thanks @Glavo. The static SIP in Scala 2 is for now stalled. It you’re interested in it, I’d encourage you to take ownership of the sip, make the modification in the proposal and try to implement it. You may also want to talk to @dotta and @dragos who had the static SIP implementation on their radar.