https://kotlinlang.org logo
#announcements
Title
# announcements
j

jdiaz

11/18/2017, 5:03 PM
If I define in Kotlin List<Int> in java is expecting List<? extends Integer>, what's the way of maintaining compatibility?
s

snrostov

11/18/2017, 5:11 PM
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

Andreas Sinz

11/18/2017, 6:08 PM
@jdiaz what do you mean with compatibility?
d

dragas

11/18/2017, 7:38 PM
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.