Reified generics in interface


#1

Hi, Is there a workaround that achieves the following:

interface Foo {
  inline fun <reified T> foo(thunk: () -> Any): Unit { }
}

#2

This may come close:

interface Foo {
    fun foo(thunk: () -> Any, klass: KClass<*>)
}

inline fun <reified T> Foo.foo(noinline thunk: () -> Any) = foo(thunk, T::class)

But you’ll need to use klass to perform your casts, etc


#3

Thanks for reply. I am trying to use the interface more as a trait, to provide some methods that can be mixed in to a class. So I want the users of the trait to be able to call foo { } directly from their class, so I don’t want the klass in the method signature that they use.


#4

Can we expect a better fix in the future?


#5

There is a KEEP for something that should help


#6

Similar proposal using KClass