I want to generify the following function:
fun ViewGroup.allRadioButtons(f: (RadioButton) -> Unit){
this.afterMeasured {
for(i in 0 until childCount){
val child = getChildAt(i)
if(child is RadioButton){
f(child)
}
if(child is ViewGroup){
child.allRadioButtons(f)
}
}
}
}
So instead of hardcoding RadioButton
, I would like to use a generic T
, like this:
inline fun <reified T> ViewGroup.allViewsOfTypeT(f: (T) -> Unit){
this.afterMeasured {
for(i in 0 until childCount){
val child = getChildAt(i)
if(child is T){
f(child)
}
if(child is ViewGroup){
child.allRadioButtons(f)
}
}
}
}
I can't do the above because reified types are not allowed in recursive functions.
How can I generify that function in Kotlin?