Skip to content

Instantly share code, notes, and snippets.

@CheolhoJeon
Created June 17, 2021 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CheolhoJeon/0d30ff495658486946c16638c1f9b6e1 to your computer and use it in GitHub Desktop.
Save CheolhoJeon/0d30ff495658486946c16638c1f9b6e1 to your computer and use it in GitHub Desktop.
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