Question Details

No question body available.

Tags

kotlin kotlin-java-interop

Answers (1)

May 7, 2026 Score: 1 Rep: 294,915 Quality: Medium Completeness: 100%

There never was any implicit conversion between java.lang.Integer and kotlin.Int. It is by design that number types must be converted to each other explicitly and not implicitly.

Numeric types are not subtypes of one another. Kotlin requires explicit conversions to avoid silent data loss and unexpected behavior.

fun f(javaInteger: Integer) {
    val kotlinInt: Int = javaInteger // does not compile!
}

The behaviour that you might be thinking of, is that Java declarations involving Integer are imported into Kotlin as Int! (or Int?). That is indeed true, but in your case, the Java declaration does not involve any Integer:

// this is a totally generic method! No Integer involved at all!
 T get(String s, Class c)

get simply gets imported into Kotlin without much change:

// from Kotlin's perspective:
fun  get(s: String!, c: Class!): T!

The type Integer only appears when you call get, which is in Kotlin code, and so Kotlin's rules apply.

In addition to as Int?, you can also

  • call .toInt() at the end to convert Integer to Int, or
  • pass in Int::class.javaObjectType instead of Integer::class.java. This evaluates to the same thing as Integer.class in Java, but is of type Class in Kotlin.

Side note: this situation is different from e.g. java.util.ArrayList and kotlin.collections.ArrayList. The Kotlin ArrayList is just a type alias for the Java ArrayList, so it is possible to implicitly "convert" between them.

fun f(javaList: java.util.ArrayList) {
    // OK!
    val kotlinList: kotlin.collections.ArrayList = javaList
}

In fact, there isn't any "conversion" being done - these are just two different names for the same type.

java.lang.Integer and kotlin.Int on the other hand, are different types.