Step #3: Adding the Constructor

Let’s add 5 properties to ToDoModel, as constructor val parameters:

To that end, modify ToDoModel to look like:

package com.commonsware.todo

import java.time.Instant
import java.util.*

data class ToDoModel(
  val description: String,
  val id: String = UUID.randomUUID().toString(),
  val isCompleted: Boolean = false,
  val notes: String = "",
  val createdOn: Instant = Instant.now()
)

Here, we have added the five constructor parameters. Four of them — all but description — provide default values, so we can supply values or not as we see fit when we create instances.

Of particular note:


Prev Table of Contents Next

This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.