如果我有一堂课,例如
data class Departments (
val customerFacing: Commercial,
val warehouse: Operational,
val accounting: Auditing)
是否有更类似于 Kotlin 的方式来实现以下目标?
val list: MutableList<Sections<*>> = arrayListOf()
if(deparments.customerFacing != null) {
list.add(Section(manager, deparments.customerFacing)
}
if(deparments.warehouse != null) {
list.add(Section(manager, deparments.warehouse)
}
if(deparments.accounting != null) {
list.add(Section(manager, deparments.accounting)
}
data class Section<T>(val manager: String, val section: T)