sorry that this is convoluted, but it's pretty clo...
# getting-started
y
sorry that this is convoluted, but it's pretty close to the real code:
Copy code
sealed class Base() {
    abstract val bar: Bar
    
    fun interface Bar {
        fun frobnicate(a: Int, b: String)
    }
}

class Derived : Base() {
    override val bar: Bar get() = ::DC // ERROR: Return type mismatch: expected 'Base.Bar', actual 'Function2<Int, String, Unit>'.
}

data class DC(val a: Int, val b: String)
vs
Copy code
sealed class Base(val bar: Bar) {
    fun interface Bar {
        fun frobnicate(a: Int, b: String)
    }
}

class Derived : Base(::DC) // works

data class DC(val a: Int, val b: String)
the second one compiles. how do I get the first one to compile? do I require an explicit cast to
Bar
? EDIT: is it because `fun interface`s get "promoted" when passed directly like this?
y
I think it has to do with Unit conversion? the constructor doesn't return Unit, but I guess function calls allow for unit conversion, while standalone values don't? Edit: nvm, even using a Unit-returning function here doesn't make it compile
FYI you can use the conversion function that gets created for every fun interface:
Copy code
sealed class Base() {
    abstract val bar: Bar
    
    fun interface Bar {
        fun frobnicate(a: Int, b: String)
    }
}

class Derived : Base() {
    override val bar get() = Bar(::DC)
}

data class DC(val a: Int, val b: String)
🤯 1
y
hey that works! would never have figured that out.
another thing that worked is removing the
fun interface
, making
frobnicate
an
abstract fun
and writing
override fun bar(a: Int, b: String) = DC(a, b)
(however
override fun bar(a: Int, b: String) = ::DC
did not)