Ellen Spertus
09/26/2022, 1:21 AMclass Person (val personalName: String?, val middleInitial: String?, val familyName: String?) {
override fun toString(): String {
val nameParts = mutableListOf<String>()
if (personalName != null) nameParts.add(personalName)
if (middleInitial != null) nameParts.add(middleInitial)
if (familyName != null) nameParts.add(familyName)
return nameParts.joinToString(separator = " ")
}
}
ephemient
09/26/2022, 1:25 AMlistOfNotNull(personalName, middleInitial, familyName).joinToString(" ")
ephemient
09/26/2022, 1:25 AMEllen Spertus
09/26/2022, 1:27 AMnull
for an introductory programming class that uses Kotlin. I was planning to mention that great article you link to and examples of people who don't have various components.Ellen Spertus
09/26/2022, 1:29 AMEllen Spertus
09/26/2022, 1:30 AMnull
is used)?ephemient
09/26/2022, 1:31 AMephemient
09/26/2022, 1:33 AMEllen Spertus
09/26/2022, 1:35 AMEllen Spertus
09/29/2022, 2:15 PMFriend
class and showing why you can't do:
val calvin = Friend("Calvin", bestFriend = hobbes)
val hobbes = Friend("Hobbes", bestFriend = calvin)