![]() Notice the error that appears when you delete the ? operator. If stated after a reference, like in our situation, it means that this property can hold a null value. To distinguish between the null references and the non-null reference, we use the ? operator. Kotlin's type system distinguishes between references that can hold null(nullable references) and those that cannot(non-null references).But what is the ? doing? To talk about that, we need to talk about null safety. The FragmentMainBinding class is created from an XML layout file I have called fragment_main. Each binding class contains references to the root view and all views that have an ID. Now that we have explained the first half, lets explain the second half.Īs stated in the official View Binding documentation, HERE, if view binding is enabled for a module, a binding class is generated for each XML layout file that the module contains.Private var _binding, we are creating a private writable property called _binding. Under the hood Kotlin will automatically create the necessary field and accessor method. When we declare a variable with either val(immutable) or var(mutable) we are actually defining a readable property and a writable property. I know that might sound a little weird but just hear me out. Kotlin does things a little differently, there are no individual fields and accessor methods, only properties. Writeable properties, which means we can read and change the values. readable properties, which means we can only read their values and not change them. ![]() There are actually two types of properties. So anything you read property think field plus accessor methods. The combination of a field and the accessor methods creates what we call a property.Enter fullscreen mode Exit fullscreen mode
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |