Invoke() functions


If I define a class with an invoke() method I can invoke it like a function

class C() {   fun invoke(): Unit = println("hello world") }

val c = C()

-> "hello world"

But if I try to invoke it directly after the constructor it doesn’t work


-> Expecting a function type, but found C

Is that a bug? It seems surprising.


Yes, it is a bug.