Hanbit the Developer
Kotlin Documentation | Interfaces 본문
Category: Concepts - Classes and objects
문서 링크: https://kotlinlang.org/docs/interfaces.html
interface Named {
val name: String
}
interface Person : Named {
val firstName: String
val lastName: String
override val name: String get() = "$firstName $lastName"
}
data class Employee(
// implementing 'name' is not required
override val firstName: String,
override val lastName: String,
val position: Position
) : Person
Resolving overriding conflicts
interface A {
fun foo() { print("A") }
fun bar()
}
interface B {
fun foo() { print("B") }
fun bar() { print("bar") }
}
class C : A {
override fun bar() { print("bar") }
}
class D : A, B {
override fun foo() {
super<A>.foo()
super<B>.foo()
}
override fun bar() {
super<B>.bar()
}
}
'Kotlin' 카테고리의 다른 글
Kotlin Documentation | Visibility modifiers (0) | 2023.05.22 |
---|---|
Kotlin Documentation | Functional (SAM) interfaces (0) | 2023.05.22 |
Kotlin Documentation | Properties (0) | 2023.05.22 |
Kotlin Documentation | Inheritance (0) | 2023.05.22 |
Kotlin Documentation | Classes (0) | 2023.05.22 |