4. Preface
- Be aware the discrepancy of interface between Java(8 later and 8 prior) and Kotlin
- Be aware how to implement interface and abstract class between Java and Kotlin
- Be aware different between interface and abstract class in Kotlin
- Know about scenario of interface and abstract class usage
9. Resolving overriding conflicts
default implementation
C only need to override bar because A already provide
default implementation
When interface has same signature function, whatever interface has default
implementation, D still override explicitly.
If D want to call default implementation, use super<T>.function(), like
super<A>.foo()
10. Discrepancy between Kotlin and Java
Kotlin Java 8 Java 8 prior
Field Final static via companion
object
Final static Final static
Property(field+accessor) Yes(but no backing field) No No
Function abstract/default/static abstract/default/static abstract
12. Difference
- Interface is stateless(they can’t have a state), abstract class is stateful(they can
have a state)
- An interface cannot specify a constructor.
- Interface can provide default implementation, but abstract function in abstract
class can’t have body
- A class can extend only one abstract class, but can implement many interface.
- From design view, interface is contract and abstract class is “is-a”