Kotlin invokes wrong overloaded java method with variable number of arguments

#1

I have two java methods:

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?

0 Likes

#2

Can you provide more details/code? It shouldn’t call second method… I tried with same type for A and B but even in this case it calls the correct method.

0 Likes

#3

<T extends Entity<?, ID>, ID extends Comparable> Optional find(GenericId<T, ID> id);

<T extends ModelWithGenericId<?, ID, S, ?>, ID extends Comparable<ID>, S extends State> Optional<T> find(GenericId<T, ID> id, S... states);

Methods in java.

Calling in kotlin from
val id = CustomId() //extended GenericId<T, ID> id
find(id)

0 Likes