lhwdev
03/05/2022, 3:34 AMinterface Super {
fun a()
}
And
class Child : Super {
override fun a() { TODO() }
}
If we add new member to Super
, it will cause a compiler error to Child
. What I want is, to have a same behavior(compiler error) even if Child
is abstract class. So I need to explicitly implement all abstract members like:
interface Super {
fun a()
fun b() // new
}
@ExplicitAbstract
abstract class Child : Super {
override fun a() { TODO() }
// if this is absent, would lead to compilation error
override abstract fun b() // if cannot implement here, mark as abstract
}
Note that I didn't think about how to mark it(here, @ExplicitAbstract
) so don't care.
Honestly, this is just an idea and I don't know if it would be useful. What do you think?raulraja
03/05/2022, 10:43 AMChild
as open. does
this cover your use case?
interface Super {
fun a()
fun b() // new
}
open class Child : Super {
override fun a() {
println("Child.a")
}
override fun b() {
println("Child.b")
}
}
class GrandChild : Child()
If you can’t implement b
in Child
, why do you want to explicitly include the abstract
empty declaration for it?raulraja
03/05/2022, 10:44 AMChild
is also an interface and not a class?lhwdev
03/05/2022, 10:49 AMSuper
) and Super
adds new abstract member, this ensures explicitly break/keep source/binary compatibility.
I'm thinking that the same thing should apply when Child
is interface.raulraja
03/05/2022, 11:04 AMdeclarationChecker
and emits warnings or errors when inherited members are not declared in the type is annotated with @ExplicitAbstract