Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

197
Vistas
Kotlin invokes wrong overloaded java method with variable number of arguments

I have two method in java:

Object get(A a)
Object get(A a, B... b)

and when I'm trying to invoke first method in Kotlin

get(someInstance)

It always invokes second method with empty second parameter.

How could I call first method from Kotlin in this case?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

First of all, this doesn't happen when methods are defined in Kotlin:

class A
class B

fun f(a: A) { println("one") }
fun f(a: A, vararg rest: B) { println("many") }

fun main(args: Array<String>) {
    f(A())
}

prints one. Searching on https://youtrack.jetbrains.com/issues?q=kotlin%20vararg%20java I can't find this exact issue (https://youtrack.jetbrains.com/issue/KT-11150 is close, but it has get(Object a) as the non-vararg overload). So I suggest you post it there if you can reproduce it.

Two possible workarounds:

  1. trying to adapt a trick from Kotlin function overloading (varargs vs single parameter):

    val a: A = ...
    a.let(::get)
    
  2. define a wrapper in Java:

    Object getNonVararg(A a) { return get(a); } 
    

and call it from Kotlin.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda