Skip to content

Instantly share code, notes, and snippets.

@Concers
Last active Jan 12, 2021
Embed
What would you like to do?
class FavoriteAuthor(_name: String, _lastname: String, _age: Int) {
var name = _name
var lastname = _lastname
var age: Int? = _age
get() {
return if (field!! > 0) field else null
}
}
val favoriteauthor = FavoriteAuthor("Franz","Kafka",-1)
println("Favorite Author: ${favoriteauthor.name} ${favoriteauthor.lastname} ${favoriteauthor.age}")
// Favorite Author: Franz Kafka null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment