0
I’m learning Kotlin, I can’t understand why the problem "Expecting a top level declaration". The result I intended was that I pointed out Bob as the oldest
data class Person(val name: String,
val age: Int? = null)
fun main(args: Array<String>) {
val persons = listOf(Person("Alice"),
Person("Bob", age = 29))
val oldest = persons.maxBy { it.age ?: 0 } }
println("The oldest is: $oldest")
I copied it just like the book but keeps returning it down
Expecting a top level declaration Expecting a top level declaration Expecting a top level declaration Expecting a top level declaration Expecting a top level declaration Expecting a top level declaration Expecting a top level declaration Expecting a top level declaration
your println is out of main function
– Lucas Miranda