i'm trying to offer two methods with similar signa...
# getting-started
t
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
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
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
thanks @Nick Allen, i'll try it out after my vacation 🙏