Inability to add methods to platform types (Util class EVERYWHERE) • Nullability problems (NullPointerException, you know it) • Mutability problems • VERY, VERY, VERY… VER(Y)BOSE. No, serious. Java is Verbose.
var lastName: String?, var phone: String?, var dateOfBirth: Date?) Kotlin Data classes = equals() + hashCode() + toString() + copy() 1 line in Kotlin VS 83+ lines in Java
Models.kt data class User(val name: String, val surname: String, val email: String) data class Address(val street: String, val zipCode: ZipCode) data class ZipCode(val prefix: String, val postfix: String)
mutable variable (getter/setter) var lastName: String? = null // mutable variable (getter/setter) val age: Int? = null // immutable (getter only) fun test(){ val user = User() // no 'new' keyword user.firstName = "Ajeje" // setter is called user.lastName = "brazof" // setter is called print("The name is ${user.firstName}") // getter is called } }
val filteredList = ArrayList<T>() for(item in this){ if(predicate(item)){ filteredList.add(item) } } return filteredList } val names = listOf("Leonardo", "Federico", "Marco", "Daniele") val l = names.filter { it == "Leonardo" }