Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumKotlingenerics variance in outSingle-choice MCQ

Given `class Box<out T>(val value: T)`, why is assigning `Box<String>` to a `Box<Any>` variable safe, and what restriction makes it sound?

class Box<out T>(val value: T) fun main() { val s: Box<String> = Box("hi") val a: Box<Any> = s println(a.value) }