I’m curious about where are valid locations in Kotlin to declare an empty method, meaning one without a body.
In the current Kotlin grammar (Grammar) the body of a method is always optional. Meaning that an empty method can be declared anywhere a method with a body can be declared. (Ditto for an abstract
method.)
However, if I try to declare an empty method at the top level, IntelliJ marks it as an error and asks me to provide a body. An empty body is fine, but that pair of braces is apparently important. Ditto if I try to declare an empty method inside another method.
Obviously interfaces typical consist of empty methods which define the interface itself. And an open
class can declare empty abstract
methods to accomplish the same thing. Those are the two examples I can come up with.
I’m asking partly out of curiosity, but also partly because not allowing empty top-level methods allows a fix to the official Kotlin grammar that avoids a fairly nasty performance degradation.