Greg Rynkowski
01/26/2022, 10:07 AM// all T - java classes implementing ViewDataBinding, each providing a static `bind` method
// ViewDataBinding - a Java abstract class (with no declaration of `bind`)
interface BindingAware<T : ViewDataBinding> {
var f: T
fun bind(v: View) {
// f = T.bind(a) // <= how to call static method provided by class behind T?
}
}
How to call static method of T, having only T?Greg Rynkowski
01/27/2022, 2:18 PMinterface ViewBindingAware<T : ViewDataBinding> {
var b: T
}
inline fun <reified T : ViewDataBinding> ViewBindingAware<T>.bindView(v: View): T {
val bindMethod = T::class.java.getMethod("bind", View::class.java)
b = bindMethod.invoke(null, v) as T
return b
}
and it works but I don't like too much reflection-based solutions and I left it on a side for now