max.cruz
04/17/2021, 6:11 PMprivate var _binding: ViewBinding? = null
private val binding get() = _binding!!
And I was wondering why this is better than just a lateinit property
(which, in my humble opinion, is more concise)
private lateinit var binding: ViewBinding
Or even if _binding
is going to be mutated to null, it would be better to use the language constructors to check the possibility. Am I missing something?Adrian Tappe
04/17/2021, 6:40 PMnull
to avoid leaks.Olivier Patry
04/17/2021, 10:31 PMlateinit
, aka the Kotlin NPE 🙃rkeazor
04/18/2021, 9:46 AMJoost Klitsie
04/18/2021, 6:30 PMJoost Klitsie
04/18/2021, 6:30 PMJoost Klitsie
04/18/2021, 6:31 PMJoost Klitsie
04/18/2021, 6:38 PMval _liveData = MutableLiveData()
val liveData: LiveData
get() = _liveData
Is bad in my opinion. It is ugly and prefixing a variable to show its visibility is (again in my opinion) inconsistent and useless, it shows people don't get the concept of interfaces, which is a way more elegant way of hiding the implementation of a certain object.Javier
04/18/2021, 10:44 PMmax.cruz
04/19/2021, 6:36 AMlateinit
fits way better, and it's more idiomatic than a backing property. My problem with this practice is that you are opening the door in your code for using !!
in more places when you are "sure that the value is never going to be null", and that breaks the NPE safety.max.cruz
04/19/2021, 6:51 AMJavier
04/19/2021, 7:03 AMJoost Klitsie
04/19/2021, 7:08 AMJavier
04/19/2021, 7:10 AMmax.cruz
04/19/2021, 7:11 AMJavier
04/19/2021, 7:12 AMJavier
04/19/2021, 7:13 AMJoost Klitsie
04/19/2021, 7:14 AMmax.cruz
04/19/2021, 7:15 AMmax.cruz
04/19/2021, 7:17 AMhttps://i.stack.imgur.com/G57CI.png▾
Joost Klitsie
04/19/2021, 7:18 AMJoost Klitsie
04/19/2021, 7:20 AMJoost Klitsie
04/19/2021, 7:20 AMJoost Klitsie
04/19/2021, 7:20 AMmax.cruz
04/19/2021, 7:28 AMmax.cruz
04/19/2021, 7:28 AMJavier
04/19/2021, 7:31 AMmax.cruz
04/19/2021, 7:35 AM