Is there a way to call super functions/properties ...
# announcements
b
Is there a way to call super functions/properties with recievers?
Copy code
open class A {
    open fun String.x() {
        // implementation
    }
}

open class B : A() {
    override fun String.x() {
        // implementation
        
        // 'super' is not an expression, it can not be used as a receiver for extension functions
        super.run { this@x.x() }
    }
}
Interestingly, when I click on the last
x
, IntelliJ highlights the
x
function name in
A
, and if I remove
super.
it'll highlight the
x
function name in
B
s
What exactly are you trying to do here anyhow? How would you call an extension on
super
in the first place? There is no instance of
super
to pass to the statically resolved extension function
b
This is what I have right now: BukkitFcItem_1_9.kt#L18 BukkitFcItem_1_7.kt#L45 Right now I'm using composition, with BukkitFcItem_1_9.TypeClass delegating to BukkitFcItem_1_7.TypeClass, but I want to change to inheritance so I can take advantage of dynamic dispatch. With inheritance, it would look something like this:
Copy code
object BukkitFcItem_1_9 {
    @Singleton
    class TypeClass @Inject constructor(
        private val items: FcItem.Factory,
        legacyMaterialInfo: LegacyMaterialInfo,
    ) : BukkitFcItem_1_7.TypeClass(
        items = items,
        legacyMaterialInfo = legacyMaterialInfo,
    ) {
        override val FcItem.craftingRemainingItem: FcItem?
            get() = when (material) {
                Material.DRAGONS_BREATH -> items.fromMaterial(Material.GLASS_BOTTLE)
                else -> super.run { craftingRemainingItem }
            }
    }
}
d
I don't think there is a syntax for this in Kotlin at the moment. You can use the following workaround: https://pl.kotl.in/zHhI2ycNS
👍 1