Skip to content

Instantly share code, notes, and snippets.

@enshahar
Created May 24, 2023 14:11
Show Gist options
  • Save enshahar/75f11a4fc68411ecd240a60fc27e3b6a to your computer and use it in GitHub Desktop.
Save enshahar/75f11a4fc68411ecd240a60fc27e3b6a to your computer and use it in GitHub Desktop.
private 멤버나 constructor는 공변성 검증 대상이 아님
class Box<out T, FUN: ()->T>(v: T, private val nextval: FUN) {
private var value: T = v
private fun log(v: T) {
println(v)
}
fun logPublic(v: T) { // Type parameter T is declared as 'out' but occurs in 'in' position in type T
println(v)
}
fun get():T {
value = nextval()
log(value)
logPublic(value)
return value
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment