https://kotlinlang.org logo
#getting-started
Title
# getting-started
b

Brian Donovan

09/16/2021, 3:56 PM
What does this mean, ViewBinding has type safety and null safety?
j

Joffrey

09/16/2021, 3:58 PM
I guess your answers are there: https://developer.android.com/topic/libraries/view-binding#findviewbyid
View binding has important advantages over using `findViewById`:
* Null safety: Since view binding creates direct references to views, there's no risk of a null pointer exception due to an invalid view ID. Additionally, when a view is only present in some configurations of a layout, the field containing its reference in the binding class is marked with 
@Nullable
.
* Type safety: The fields in each binding class have types matching the views they reference in the XML file. This means that there's no risk of a class cast exception.
b

Brian Donovan

09/16/2021, 5:31 PM
ty
15 Views