lokesh
09/04/2026, 12:48 AMreified thing, in, out, where and I thought that's enough.
I'm watching `dave leeds`'s video on "reified type parameters" and shocked to see yet another thing List<*> now wtf is * ? yet another wildcard?min
09/04/2026, 3:02 AMExample<*> is Example<out Bound> wheremin
09/04/2026, 3:03 AMclass Example<T: Bound>(val impl: T)ephemient
09/04/2026, 5:00 AMephemient
09/04/2026, 5:01 AMVampire
09/04/2026, 8:38 AMExample<*> more like Java's Example<?> and not Example?
There is no raw type-equivalent in Kotlin, is there?Vampire
09/04/2026, 8:45 AMreified.
At runtime in JVM-worlds a generic type is erased, so generic type checks are only a compiler check and at runtime you only have the raw type without generic parameter.
With Kotlin it is by default the same, at runtime you do not have access to the actual type used for the generic parameter.
With reified you can use the type.
For example this will not work:
fun <T> T.getJavaClass() = T::class.java
but this does work:
inline fun <reified T> T.getJavaClass() = T::class.java
Or this will work but is an unchecked cast:
fun <T> cast(o: Any) = o as T
while this is a type-safe cast:
inline fun <reified T> cast(o: Any) = o as TCLOVIS
09/09/2026, 12:32 PM* means "I don't care what it is". List<*> is a list of "I don't know, could be anything". So when you read from it, it behaves as a List<Any?> (you don't know what you'll get) and when you write to it, it behaves as a List<Nothing> (you don't know what you're alllowed to put in there, so you're allowed to put nothing).CLOVIS
09/09/2026, 12:32 PM_ but that just means "hey compiler, I'm too lazy to write the type that goes there, figure it out yourself", it's not special in any other wayVampire
09/09/2026, 1:12 PMval foo: MutableList<_> = mutableListOf("foo")
fails compilation with "Unresolved reference".CLOVIS
09/09/2026, 1:17 PM_ is not legal everywhere, I don't know the exact rule. I think it's mostly when calling something that has ambiguous type parameters.
fun <T, U> foo(input: T): U {
TODO()
}
val a = foo("foo")
// Compilation error: Cannot infer type parameter U. Specify it explicitly.
val b = foo<_, Int>("bar")
Here T is most definitely String , and the compiler can figure that out itself, but it has no way of knowing what the return type U would beVampire
09/09/2026, 1:46 PMval b: Int = foo("bar") but, yeah, I know that place, but not for the List<...> case.CLOVIS
09/09/2026, 3:20 PMb: Int is nicer in this particular example. I usually encounter _ when using self-types or other recursive type parameters