I’m looking for a syntactic sugar or something else to facilitate exposing private/internal properties as an upcasted instance.
Suppose there exist a mutable array in a class:
class Person{
private val _addressList = MutableList<String>()
}
If we need to expose _addressList
then should write a function or another property which upcasts addressList
as List<String>
fun getAddressList = _addressList as List<String>
// OR
val addressList = _addressList as List<String>
Due to DRY principle, I’m curious to find a reusable way of exposing upcasted properties to avoid duplicating exposedProperty as List<String>
everywhere in my code.