Dmytro Serdiuk
04/17/2023, 10:49 PMLandry Norris
04/18/2023, 12:03 AMLandry Norris
04/18/2023, 12:05 AMDmytro Serdiuk
04/18/2023, 12:26 PMDmytro Serdiuk
04/18/2023, 12:26 PMLandry Norris
04/18/2023, 1:11 PMclass Holder<T>(value: T) {
val something: Any = value
fun getValue(): T = something as T
}
Code written on my phone, so could have problems.
When you call getValue on a Holder<Int>, the compiler expects the return type to be Int, since at the call site, the type is known. The cast inside of getValue doesn't know it's an Int, so you're just promising the compiler 'whatever type it's returning, I know it matches T'.Dmytro Serdiuk
04/18/2023, 1:13 PM