CLOVIS
09/12/2024, 9:41 PMtypealias NullableValue<T> = TypedValue<T, KClass<out T & Any>?>
typealias NonNullValue<T> = TypedValue<T & Any, KClass<out T & Any>>
typealias NullValue = TypedValue<Nothing?, Nothing?>
class TypedValue<T : Any?, out K : KClass<out T & Any>?>(
val value: T,
val type: K,
)
// Compiles, and I understand why:
val n1: NullableValue<Int> = TODO()
val n3: NonNullValue<Int> = TODO()
val n5: NullValue = TODO()
// Does not compile, and I understand why:
val n4: NonNullValue<Int?> = TODO()
However, there's this one, that I don't understand:
val n2: NullableValue<Int?> = TODO()
Type argument is not within its bounds.
Expected:Any
Found:Why does it expectInt?
Any
? From what I understand:
• NullableValue<Int?>
• is expanded to TypedValue<Int?, KClass<out Int>?>
• To me, that seems to satisfy all type bounds.
So, why is it forbidden?PHondogo
09/12/2024, 11:32 PMabstract class TypedValue<T : Any?, out K : KClass<out T & Any>?>
class TypedValue2<T> : TypedValue<T, KClass<out T & Any>?>()
val n1: TypedValue2<Int?> = TODO()
Daniel Pitts
09/13/2024, 2:02 AMDaniel Pitts
09/13/2024, 2:07 AMinterface TypedValue<T : Any?, out K : KClass<out T & Any>?>
interface NullableValue<T> : TypedValue<T, KClass<out T & Any>?>
interface NonNullValue<T> : TypedValue<T & Any, KClass<out T & Any>>
interface NullValue : TypedValue<Nothing?, Nothing?>
val n1: NullableValue<Int> = TODO()
val n2: NullableValue<Int?> = TODO()
val n3: NonNullValue<Int> = TODO()
val n4: NonNullValue<Int?> = TODO()
val n5: NullValue = TODO()
Daniel Pitts
09/13/2024, 2:11 AMCLOVIS
09/14/2024, 9:31 AM