Marko Mitic
10/12/2019, 8:02 PM@Binds
). So far, I can make it work with Kotlin types and even Java ones but it fails for generic Java types (like List<*> and ArrayList<*>). Is this limitation of generics system or am I doing something wrong?
function: fun <C : I, I: Any> bind(clazz: Class<C>, iface: Class<I>)
usage: bind(ArrayList::class.java, List::class.java) //kotlin types, works fine
bind(java.util.ArrayList::class.java, java.util.List::class.java) // error: inferred type ArrayList<*> is not a subtype of List<*>
marstran
10/12/2019, 8:04 PMMarko Mitic
10/12/2019, 8:05 PMType parameter bound for C in fun <C : I, I : Any> bind(clazz: Class<C>, iface: Class<I>): Unit
is not satisfied: inferred type ArrayList<*> is not a subtype of List<*>
marstran
10/12/2019, 8:11 PMMarko Mitic
10/12/2019, 8:15 PMmarstran
10/12/2019, 8:25 PMMarko Mitic
10/12/2019, 8:26 PMmolikuner
10/12/2019, 8:32 PMinline fun <C : I, I: Any> bind(clazz: KClass<C>, iface: KClass<I>) = bind(clazz.java, iface.java)
If you need to do this often, you may want to publish an extra artifact with those overloaded functions.Marko Mitic
10/12/2019, 8:40 PMType parameter bound for C in inline fun <C : I, I : Any> bind2(clazz: KClass<C>, iface: KClass<I>): Unit
is not satisfied: inferred type ArrayList<*> is not a subtype of List<*>
bind2(java.util.ArrayList::class, java.util.List::class)
Timmy
10/13/2019, 11:05 PMfun <I: Any> bind(iface: Class<I>) = BindOp(iface)
class BindOp<T>(val t: T)
infix fun <I:Any, C:I> BindOp<I>.to(clazz: Class<C>): Unit = TODO()