This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Task( | |
val description: String, | |
val assignedTo: AssignedTo | |
) | |
sealed class AssignedTo(val name: String) { | |
object Nobody : AssignedTo("") | |
class User(name: String) : AssignedTo(name) | |
} | |
fun main() { | |
val buyMilk = Task("Buy milk", AssignedTo.Nobody) | |
val writePost = Task("Write post", AssignedTo.User("le0nidas")) | |
print(buyMilk, writePost) | |
// Task 'Buy milk' is assigned to | |
// Task 'Write post' is assigned to le0nidas | |
} | |
private fun print(vararg tasks: Task) { | |
tasks.forEach { task -> | |
println("Task '${task.description}' is assigned to ${task.assignedTo.name}") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment