14.findViewById的过去及未来

May 17, 2021 · View on GitHub

We have lots of alternatives for this, and you may wonder why do we need another solution. Let’s compare the different solutions based on these criteria: null-safety, compile-time safety, and speed.

Column 1ButterKnifeKotlin SyntheticsData BindingfindViewByIdView Binding
Fast❌ *❌ *
Null-safe
Compile-time safe✅ **

* ButterKnife and Data Binding solutions are slower because they use an annotation-based approach ** findViewById() is compile-time safe since API 26 because we don’t need to cast the type of view anymore.

https://juejin.cn/post/6905942568467759111

https://medium.com/mobile-app-development-publication/how-android-access-view-item-the-past-to-the-future-bb003ae84527

参考