In Java, it is possible to declare an object of a ...
# announcements
c
In Java, it is possible to declare an object of a type
Something<?>
to say that the generic is ignored. Is there any similar syntax in Kotlin? If so, where can I find documentation that explains how to use it?
a
Something<*>
not sure of document
s
The simple answer is it depends
☝🏼 3
d
Something<*>
Something<Any>
Something<Unit>
Something<Nothing>
Depends on what ignore means I guess.
s
The wildcard
*
means
out Any?
for covariant type parameters (when getting a value, you can safely assign it to a variable of type
Any?
) or
in Nothing
for contravariant type parameters (there is no safe way to set a value safely). If you are planning to never call any methods that use a type-parameter on an interface having that type parameter, use
*
for that type parameter fro the declaration of your variable/parameter/property.