I'm new to Kotlin and I'm trying to figure out how to do something if a variable is null. This is what I'm trying to do
private var loggedInUser: User? = null
fun createActivity(activity: Activity) {
loggedInUser?.activities?.put(activity.id, activity)
//set loggedInUser.activities = hashMapOf() if null
}
Here's the User class
data class User(
val firstname: String = "",
val lastname: String = "",
val email: String = "",
val password: String = "",
val id: String = UUID.randomUUID().toString(),
val activities: MutableMap<String, Activity> = hashMapOf())