Shawn
11/29/2018, 2:56 AMinline fun <reified T> Any.castTo() = this as T
but a) that probably won’t work, b) why do you need this as a function?tyjka
11/29/2018, 3:02 AMholder.castTo(NetworkStateViewHolder).bindTo(networkState)
looks more fluid to me than (holder as NetworkStateViewHolder).bindTo(networkState)
Later is more idiomatic though.Shawn
11/29/2018, 3:15 AMholder.castTo<NetworkStateViewHolder>()
.bindTo(networkState)
tyjka
11/29/2018, 3:32 AMShawn
11/29/2018, 3:35 AMnull
if the class cast fails, you’ll just have to switch from the function to (foo as? bar)?.baz()...
anyhow or add an additional castToOrNull<>()
functiontyjka
11/29/2018, 4:21 AM