Created
June 17, 2021 06:23
-
-
Save CheolhoJeon/0d30ff495658486946c16638c1f9b6e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package chap5.CompanionObjects | |
import atomictest.trace | |
class ZIClosed : ZI { | |
override fun f() = "ZIClosed.f()" | |
override fun g() = "ZIClosed.g()" | |
} | |
class ZIDelegation { | |
companion object: ZI by ZIClosed() | |
fun u() = trace("${f()} ${g()}") | |
} | |
class ZIDelegationInheritance { | |
companion object: ZI by ZIClosed() { | |
override fun g() = | |
"ZIDelegationInheritance.g()" | |
fun h() = | |
"ZIDelegationInheritance.h()" | |
} | |
fun u() = trace("${f()} ${g()} ${h()}") | |
} | |
fun main() { | |
ZIDelegation.f() | |
ZIDelegation.g() | |
ZIDelegation().u() | |
ZIDelegationInheritance.f() | |
ZIDelegationInheritance.g() | |
ZIDelegationInheritance().u() | |
trace eq """ | |
ZIClosed.f() ZIClosed.g() | |
ZIClosed.f() | |
ZIDelegationInheritance.g() | |
ZIDelegationInheritance.h() | |
""" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment