https://kotlinlang.org logo
Title
m

Mark

01/21/2023, 2:21 AM
Ideally I want to declare an extension function so I can call like `FooBinding.inflateOrNull(): FooBinding?`but I can’t see how to do this. The best I have is:
private fun <V: ViewBinding> inflateOrNull(inflateLambda: (LayoutInflater) -> V): V? {
    try {
         return inflateLambda(layoutInflater)
    } catch (e: Exception) {
         // some dodgy device that cannot find a resource
         return null
    }
}
e

ephemient

01/21/2023, 3:00 AM
FooBinding
needs to have a companion object for you to be able to write an extension that can be called like
FooBinding.inflateOrNull()
. since it's a Java class, it doesn't have a companion