Hi All, consider the following function signature:...
# language-evolution
u
Hi All, consider the following function signature:
Copy code
inline fun <reified T: Fragment> replaceFragment(
        name: String = T::class.java.name
    )
Why do I need
inline refied
in the signature? I do understand that T.class.java can not work on an erased type but, If I understand correctly, kotlin would insert the default parameters at call site where the type information is readily available. If I am not mistaken in my assumptions, I propose to lift the restriction on generic types for when they are used in default parameter definitions.
e
default parameters are resolved in the called function, not in the caller
👍 2
i
Without
reified
the function could be called with non-reified T.
u
Thanks @ephemient, checked decompiled bytecode and found
replaceFragment$default
Interesting. Learned something new today 🙂 Somehow I was sure the compiler would insert the missing parameters at call site with all the consequences regarding changing default parameters in a library. Good to see that kotlin is again a bit smarter then me 🙂
e
well it does make some things harder, such as https://youtrack.jetbrains.com/issue/KT-18695, but overall I think it's a good choice
e
There are occasional cases where you want the default parameters on the call-site. We call those "inline default parameters". You can vote for this feature and/or add your use-cases (if any) here: KT-50113 Inline default parameters for functions