You cannot set the generic through reflection, because the function does not exist at runtime. The function is an inline function which gets inlined, i.e. every call of the function is replaced by its body.
For instance, when you write
PeriodicWorkRequestBuilder<com.demo.Work>(someDuration).build()
somewhere in your code, the compiled code will not contain a function call of PeriodicWorkRequestBuilder
inline function (which does not exist in the compiled code), but instead there will be byte code that can be decompiled to
PeriodicWorkRequest.Builder(com.demo.Work::class.java, someDuration).build()
You cannot pass in a generic class via reflection into the inline function, because for the inlining, the compiler has to know the exact type at compile-time.
So, if you want to pass in a generic Class
parameter, you cannot use the inline function. But that's not at all necessary, because you can just use the code inside the function, i.e.
PeriodicWorkRequest.Builder(Class.forName("com.demo.work"), someDuration)
This manual inlining of an inline function should work in every possible case, because everything inside an inline function has to be accessable everywhere where you could use the inline function. Otherwise, the inlining of the inline function by the compiler would lead to incorrect code.