platformStatic?


#1

Looks like this is a new way to make "real" static methods at the JVM level instead of normal methods of class objects?

Great feature, I ran into the need for this before. But isn’t platformStatic kind of an ugly name? I know Javascript doesn’t have any notion of a static method and controlling the exact conversion into JVM bytecodes is thus platform specific, but it seems the annotation could just be named “static” as the concept is meaningless in JS anyway. Code translated from Java would look a lot more natural.


#2

It would be confusing. It is not a static method in Kotlin, it can implement an interface, override a method from base class, etc. It is only made accessible from Java as a static method call, so one can design Java APIs and develop libraries in Kotlin. There are other "platform" annotations, like platformName for example. There is another case when you need to place annotation on a backing field, without a notion of a field in Kotlin.

I would probably make it single annotation “platform” that gets vararg of other annotations:

platform(static, name(“foo”))
fun bar() = … // method can be invoked from Java as a static method with the name foo

platform(field(Inject, name(“myField”)))
val prop = … // backing field is called myField and it has @Inject annotation.

But this is still not decided and can change.