Is there any other way of achieving similar result...
# codingconventions
g
Is there any other way of achieving similar results to that?
Copy code
inline fun <reified T : Any> withType(
        t: KClass<T> = T::class
) = ...

inline fun <reified T1 : Any, reified T2 : Any> withType(
        t1: KClass<T1> = T1::class,
        t2: KClass<T2> = T2::class
) = ...

inline fun <reified T1 : Any, reified T2 : Any, reified T3 : Any> withType(
        t1: KClass<T1> = T1::class,
        t2: KClass<T2> = T2::class,
        t3: KClass<T3> = T3::class
) = ...

inline fun <reified T1 : Any, reified T2 : Any, reified T3 : Any, reified T4 : Any> withType(
        t1: KClass<T1> = T1::class,
        t2: KClass<T2> = T2::class,
        t3: KClass<T3> = T3::class,
        t4: KClass<T4> = T4::class
) = ...
c
What output are you looking for with these functions? This is totally valid:
Copy code
inline fun <reified T : Any> withType(vararg classes: T) = { ... }
Would be called as such:
Copy code
withType(String::class, Int::class)
g
Yeah, that is the first version of what I did, and works just like that. I was intending to make it a bit tidier by using reification, and call it like
Copy code
withType<String, Int>()
Instead
Cutting away the
::class
bits