2

This two functions conflicts with each other. Is there a workaround for this issue?

inline fun <reified T: Any> foo() = ...
inline fun <reified T: Any, reified I: Any> foo() = ...

Thanks!

Edit:

I found convenient(at least for me) solution for this issue:

inline fun <reified T: Any> foo() = foo<T, MyDefaultType>()
inline fun <reified T: Any, reified I: Any> foo(type1: KClass<T> = T::class, type2: KClass<I> = I::class) = ...

It can be even concise if you choose to add only one parameter.

Later you can use it like this:

val x = foo<A, B>()
val y = foo<C>()

That's what I need.

2 Answers 2

5

These functions have identical signatures from the compiler point of view. A type parameter is not part of a signature of a function; it can be inferred by the compiler automatically, and therefore does not serve to disambiguate calls to different overloads.

You need to assign different names to those functions.

Sign up to request clarification or add additional context in comments.

Comments

0

Add the annotation @JvmName("foo2") to one of the functions.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.