sindrenm
07/03/2018, 11:49 AMdata class Person(
val name: String,
val dateOfBirth: Date? = null
)
val people = listOf<Person>()
fun printNameAndDob(name: String, dob: Date) {
println("Name: $name, DOB: $dob")
}
people.filterNot { it.dateOfBirth == null }
.forEach { printNameAndDob(it.name, it.dateOfBirth) } // this won't work as dateOfBirth could be null
Are there any smart tricks I could use to “smart cast” the property somehow? Thanks! ❤️ 😀