How would I go about implementing something like t...
# getting-started
m
How would I go about implementing something like this:
Copy code
fun <R> convertTo(): R {
    return convertImpl()
}

fun convertImpl(): Int {
    // ...
}

fun convertImpl(): String {
    // ...
}
Is there an easy way to do it or will I have to just use a when statement and make R reified and add a branch for each implemented type?
j
If it were the other way around I guess polymorphism would be best, but since in your case the call site is supposed to decide the output type, you might want a
when
on the reified
R
class.