I have a generic function which needs to instantiate an object of its generic argument and pass it to an instance of some interface.
As far as I know, the only way to instantiate that generic object is making the function inline and reifying that type parameter. But I do not want to expose the implementation of that interface.
The problem is that inlined functions can not use internal classes.
What I basically want to is this:
/* The interface I want to expose */
interface Params<T> {
val doc: T
}
/* The implementation I do not want to expose */
internal class ParamsImpl<T> (override val doc: T) : Params<T>
/* The function */
inline fun <reified T> doSomething(init: Params<T>.() -> Unit) {
val doc= T::class.java.newInstance()
val params = ParamsImpl(doc) // Can't compile since ParamsImpl is internal
params.init()
}