I'm new to Scala, and there's something I'm having trouble figuring out. I have the following method:
def updateSongCount(song : Song) {
if(this.listeningCountMap.contains(song)) {
this.listeningCountMap(song) += 1
}
else
{
this.listeningCountMap += (song -> 1)
}
}
listeningCountMap is defined like this:
var listeningCountMap = Map[Song, Int]()
Now, the thing is Song is a class type and it has several parameters (like title, singer, etc). When I do the contains, even if all the parameters are the same between the two songs - it adds them as two seperate entries. I'm coming from C# and I'm used to having to override GetHashCode and Equals in order for contains to understand when two instances of my class are considered equal, and I suppose what I'm missing is the equivalent for that in scala. Could you please tell me how do we do that in Scala? Thanks!