Invoke() functions


#1

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()
c()

-> "hello world"


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

C()()

-> Expecting a function type, but found C


Is that a bug? It seems surprising.


#2

Yes, it is a bug.