arve
01/21/2025, 1:26 PMinterface Alphabet {
fun a(): String
fun b(): String
// and many more
fun z(): String
}
I thought I had a really bright idea, since the following is valid syntax:
class A : Alphabet by TODO("NOPE") {
override fun a() = "a"
}
I was hoping the delegation would act as with actual objects, routing calls to the override if they were present, and throwing NotImplementedError otherwise. Unfortunately, the TODO()
is evaluated on instantiation of A() and not during method call đ
// Hoping for
A().a() == "a" // true
A().b() // NotImplementedError
// but got
A() // NotImplementedError
Does anyone have an elegant way to partially implement an interface and default to NotImplementedError for the rest, without explicitly doing so for every single method?ephemient
01/21/2025, 1:40 PMephemient
01/21/2025, 1:40 PMephemient
01/21/2025, 1:41 PMarve
01/21/2025, 1:41 PMTODO
âing all methods, and making a âwrappingâ interface. I ended up doing the latter.arve
01/21/2025, 1:42 PMinterface TinyAlphabet { fun a(): String }
and expecting that in the calling code instead.Daniel Pitts
01/21/2025, 2:23 PMDaniel Pitts
01/21/2025, 4:19 PM