Reputation: 389
I have the following recursive call written in Scala:
def calculateFingerPrint(t: Tree):Int =
{
if(t.isInstanceOf[Leaf])
calculateIDS(t).hashCode()
else if(t.isInstanceOf[OtherNode])
//error --> calculateIDS(t).concat(calculateFingerPrint(t.children.head).toString()).hashCode
}
def calculateIDS(t: Tree):String= {
//returns some string
}
The commented line is throwing type mismatch error and saying Found: Anyval Required:Int
.
Can anyone please tell what is the problem here?
Upvotes: 0
Views: 159
Reputation: 27356
You need a final else
clause to return the default value if t
is not Leaf
or OtherNode
.
A match
expression would be better than using isInstanceOf
calls.
Upvotes: 2