If I define in Kotlin List<Int> in java is e...
# announcements
j
If I define in Kotlin List<Int> in java is expecting List<? extends Integer>, what's the way of maintaining compatibility?
s
Looks like
MutableList<Int>
in kotlin is same as java
List<Int>
. Btw,
List<Int>
in java can be treated as one of this types in Kotlin: -
List<Int>
-
List<Int>?
-
List<Int?>
-
List<Int?>?
-
MutableList<Int>
-
MutableList<Int>?
-
MutableList<Int?>
-
MutableList<Int?>?
a
@jdiaz what do you mean with compatibility?
d
The following in kotlin
Copy code
class KTesty
{
    fun foo(bar : Int)  {   }
}
is compiled into this in java
Copy code
public final class KTesty {
   public final void foo(int bar) {
   }
}
Interestingly enough, you can't pass primitive values as generics in java, as a result, when when you compile the following in kotlin
Copy code
val list = ArrayList<Int>()
list.add(bar)
val result = list[0]
You get this in java
Copy code
ArrayList list = new ArrayList();
list.add(bar);
Integer result = (Integer)list.get(0);
Anyways, you shouldn't worry about java -> kotlin or kotlin -> java calls, as both of them are interchangeable.