https://kotlinlang.org logo
#getting-started
Title
# getting-started
t

tipsy

07/05/2021, 8:22 PM
i'm trying to offer two methods with similar signatures:
Copy code
inline fun <reified T : Any> queryParam(key: String) = ...
fun queryParam(key: String) = ...
in kotlin this works fine, but both mockk and mockito get confused, it's random which one of the methods get picked. is there any way of dealing with this?
my current way of dealing with is to offer the reified versions as extension functions, but it's not ideal
n

Nick Allen

07/05/2021, 9:38 PM
Could you clarify what the mocking libraries are getting confused about? What does it mean for a method to "get picked"? Neither mocking library is able to mock inline functions, since inline functions don't actually exist in the JVM byte code.
n

Nick Allen

07/06/2021, 7:43 PM
Try:
Copy code
@JvmName("queryParam-inline")
inline fun <reified T : Any> queryParam(key: String) = ...
fun queryParam(key: String) = ...
It won't have the same JVM signature that way. The '-' makes it so you can't accidentally call it from Java. Seemed to work though I didn't give it that many test runs. Btw, "inline functions don't actually exist in the JVM byte code" was clearly incorrect, sorry. It's there, it's just not invoked at Kotlin call sites.
t

tipsy

07/12/2021, 9:50 PM
thanks @Nick Allen, i'll try it out after my vacation 🙏