I'm currently writing a DSL for a library and I'd like to supply type metadata using reified type parameters like this:
val config = Config.create()
.consumerFor<MyType>{
// consume
}
My problem is that i can only use the reified
keyword in inline
functions and in an inline
function I can't use instance fields like this:
inline fun <reified T> consumerFor(consumer: (T) -> Unit) {
consumers.put(T::class.java, consumer)
return this
}
because I get an error:
Public-API inline function cannot access non-public-API 'private final val consumers...
It seems so far that I can't use reified type parameters where they would be most useful. Is there a workaround for this?