Type mismatch error in recursive function in scala

167 Views Asked by At

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?

1

There are 1 best solutions below

2
On BEST ANSWER

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.