Unable to reference companion object methods

Syntactically it would be A.Factory:bb but it will not work. At first, bb is a A.Factory.() -> Int while () -> Int is required.

Secondly, callable references to object members are not supported at the moment as the Kotlin compiler says. Here's a parent task for all callable members tasks: https://youtrack.jetbrains.com/issue/KT-1183.


In Kotlin 1.4+ you can use process(A::bb).

In 1.1.2+ you can use process(A.Factory::bb) or process((A)::bb).


Not so long after this question was asked Kotlin 1.1 was released with support for bound callable references:

  • https://github.com/JetBrains/kotlin/blob/master/ChangeLog.md#11-m01-eap-1
  • https://blog.jetbrains.com/kotlin/2016/07/first-glimpse-of-kotlin-1-1-coroutines-type-aliases-and-more/
  • http://kotlinlang.org/docs/reference/whatsnew11.html#bound-callable-references
  • http://kotlinlang.org/docs/reference/reflection.html#bound-function-and-property-references-since-11

Kotlin 1.1.2 came with a fix for KT-15951, meaning that since then you can call process(A.Factory::bb).

There is also KT-13934 targeted for Kotlin 1.4, to support process(A::bb).

Tags:

Kotlin