Data classes
Often, we create a class whose only purpose is to store data, such as, data retrieved from a server or a local database. These classes are the building blocks of application data models:
class Product(var name: String?, var price: Double?) {
override fun hashCode(): Int {
var result = if (name != null) name!!.hashCode() else 0
result = 31 * result + if (price != null) price!!.hashCode()
else 0
return result
}
override fun equals(other: Any?): Boolean = when {
this === other -> true
other == null || other !is Product -> false
if (name != null) name != other.name else other.name !=
null -> false
price != null -> price == other.price
else -> other.price == null
}
override fun toString(): String {
return "Product(name=$name, price=$price)"
}
} In Java, we...