Change Kotlin local default

Probably this topic is discussed elsewhere but I can’t find that.

My proposal is to allow @JvmStatic annotation to companion object level to avoid creating a new class.

Moreover let the ability to define a own annotations to override default visibility or make method open. This can be a base work for “kotlin-spring” plugin and can be helpful in other development scopes.

  • Supporting @JvmStatic on regular class members wouldn’t work. The annotation only controls the generated bytecode without changing the semantics from the Kotlin point of view, and regular class members have different semantics compared to companion object members. If we wanted to support statics without declaring a companion object, that would have to be a language feature, not an annotation.
  • Annotations for making classes open are being worked on right now and will likely be supported in 1.0.5.
  • What’s your use case for changing visibility through annotations? Right now we have no plans to support something like that.

@JvmStatic proposal is only for objects and will be an alias to apply @JvmStatic to all methods.

Eg:

    object a{
        
        @JvmField
        val i=1
        
        @JvmStatic
        fun b()=Unit

        @JvmStatic
        fun c()=Unit
    }

become

    @JvmStatic // implies @JvmField ?
    object a{
        
        val i=1
        
        fun b()=Unit

        fun c()=Unit
    }

same for companion object and @JvmField annotation.

This is not on our current roadmap, but you’re welcome to file a feature request.