Junior — Senior
Compilation check and error correction in Kotlin program
livecode
Task condition
It is necessary to determine whether the provided Kotlin code fragment compiles, and if there are errors, to correct it.
class Task(var id: Long, val name: String)
val numbers = mutableListOf(1, 3, 5)
val taskSet = HashSet<Task>()
fun main() {
val firstTask = Task(1, "Task")
val secondTask = Task(1, "Task")
taskSet.add(firstTask)
taskSet.add(secondTask)
numbers.add(7)
numbers.forEvery { item ->
if (item == 3) {
return@forEvery
}
println("$item")
}
println("tasks contains ${taskSet.size} elements")
println("Done!")
}
synchronized fun <reified T> List<T>.forEvery(itemAction: (T) -> Unit) {
this.reversed().forEach { itemAction(it) }
}