Reputation: 1579
Is it possible to declare generic wildcards in Kotlin like this code in Java:
List<Integer> a = new ArrayList<>();
List<? extends Number> b = a;
Upvotes: 22
Views: 19836
Reputation: 2935
The equivalent in Kotlin would be like this:
val a = ArrayList<Int>()
val b: ArrayList<out Number> = a
Upvotes: 28
Reputation: 20140
Kotlin doesn't have wildcards, it uses the concepts of declaration-site variance and type projections instead.
Please check the documentation, covers pretty extensively.
Kotlin provides so called star-projection
val a = ArrayList<Int>()
val b: ArrayList<out Number> = a
Upvotes: 10