Can I create a case class usefull just for an Collecetion (read HashSet
) and a class that extends this case class to store usefull information?
I mean something like this:
case class User(id: String)
class UserInfo(id: String) extends User(id) {
var time = 0
var sum = 0
}
I just want to use UserInfo to store information about an User inside an HashSet, but using the case class implementation with all usefull method already implemented for collection (aka equals
and hashCode
)
Following Yuval Itzchakov comment:
abstract class User(val id: String) {
private var time = 0L
private var sum = 0L
def addTime(_time: Long) = time += _time
def addSum(_sum : Long) = sum += _sum
def getTime() = time
def getSum() = sum
}
case class UserInfo(override val id : String) extends User(id)
private vars
because I want to guarantee that I can just add information (same for getters)