Apparently I need to ask something the third time ...
# announcements
c
Apparently I need to ask something the third time today: Is there any useful application to kinda “redeclaring” a method in an interface extending another interface or is it just a “cosmetic” thing? E.g.
e
as usual, in types can be made more general, out types can be made more specific
in your example though, there's no possibility of that so it's nearly the same whether you declare
override fun a()
or not
aside from bytecode and reflection, it shouldn't be an observable difference
c
Just as I thought, thanks!
j
And let’s not forget: documentation. By redeclaring the function, you can document it to provide a more specific documentation, clarifying what that function is supposed to do on implementations of B.
t
I just found that when redefining
fun a
in
interface B
, you also have the opportunity to act on the default behavior of the function: • If
A
defines a default implementation of
fun a
and
B
redefines
fun a
without a body, then implementations of
B
must define
fun a
. • If
A
and
B
both have a default impl of
fun a
, then its the default impl of
B
that's used. You have the opportunity to call the default of
A
with
super.a()
.