Proper way to use a constructor to manually initialize a list in a ViewModel class

I want to manually build a custom list in my constructor (maybe somewhere else if you have a suggestion) that populates my MutableList variable once the class is created.

class MaleActivityViewModel : ViewModel() {
    var servicePosition: Int = 0
    var priceLowEnd: Int = 0
    var priceHighEnd: Int = 0
    val currency: String = Resources.getSystem().getString(R.string.currency)
    private lateinit var serviceTextListMale: List<String>

    init {
        val haircut: String = Resources.getSystem().getString(R.string.service_haircut)
        val facial: String = Resources.getSystem().getString(R.string.service_facial)
        serviceTextListMale = listOf(haircut, facial)
    }
}

Is this the proper way of doing it? More effective way?

You don’t need lateinit if you initialize within the init block. Otherwise this looks ok.

2 Likes