Wpis z mikrobloga

@koziolek666: A jak rozwiązywane są konflikty, gdy np rozszerzasz klasę, która ma tę samą nazwę metody co delegowany interface?

interface Delegated
{
    function nonConflicting()
    function implementedInChild()
    function implementedInParent()
}
class DelegatedImpl implements Delegated
{
    function nonConflicting() { echo 'nonConflicting delegated' }
    function implementedInChild { echo 'implementedInChild delegated' }
    function implementedInParent { echo 'implementedInParent delegated' }
}
class Parent
{
    function implementedInParent() { echo 'implementedInParent Parent' }
}
class Child extends Parent
@MacDada:

1. Jeżeli metoda jest zaimplementowana w klasie rozszerzającej/implementującej to nie zostanie nadpisana.
2. Jeżeli klasa rozszerza inną klasę i implementuje interfejs, w wyniku czego mamy konflikt nazw, to nic się nie stanie. Kotlin posiada "optymistyczne rzutowanie", czyli jeżeli obiekt ma metodę o danej nazwie to uznaje się, że można go bezpiecznie rzutować na dany typ:

fun main(args: Array) {
val i:I = SubC();
i.m()
}

interface I{
fun m();
}