June 2018
Intermediate to advanced
316 pages
6h 34m
English
Sometimes, we need to initialize properties after class initialization and don't want to create a nullable type, for instance, if we use dependency injection:
@Inject lateinit var coffee: Coffee
It's better to use a primary constructor here, so as to avoid creating an instance without initialized properties:
class CoffeeShop @Inject constructor(val coffee: Coffee) {
But in Android, a constructor for classes, such as Activity and Service ...
Read now
Unlock full access