why can't functions defined as such: ```fun foo() ...
# getting-started
h
why can't functions defined as such:
Copy code
fun foo() = true
be referenced as such:
Copy code
val bar: () -> Boolean = foo
? or conversely:
Copy code
interface Foo {
    val bar: () -> Boolean
}

object Bar : Foo {
    override fun bar() = true // nope. why not?
    override val bar = { true } // yep
}
d
because
( )->Boolean
is function that returns boolean while
true
IS boolean
a
one is a function and the other is a property holding a function reference
h
i thought all functions WERE properties in the jvm?
a
not in a way that is significant here
kotlin properties are implemented as jvm methods generally, so more like the other way around for this case
you can get a function reference using
::
if you need one
h
righto, thanks for reminding me of that
👍 1
a
also a common gotcha in this area is that
foo::bar != foo::bar
- they're different instances
so be careful if you're trying to
collectionOfFunctionReferences.remove(foo::bar)