Kotlin wildcards for variables

Is it possible to declare common wildcards in Kotlin, like this code in Java:

List<Integer> a = new ArrayList<>(); List<? extends Number> b = a; 
+5
source share
2 answers

The equivalent in Kotlin would be:

 val a = ArrayList<Int>() val b: ArrayList<out Number> = a 
+9
source

Kotlin does not have wildcards; instead, it uses the concepts of deviation from declarations and types.

Please review the documentation, which covers quite extensively.

Kotlin provides so-called stellar projection

 val a = ArrayList<Int>() val b: ArrayList<out Number> = a 
+3
source

Source: https://habr.com/ru/post/1268058/


All Articles