I have the following two methods, how can I call the method defined in DocsObj into DistanceObj?
The first object is:
object DocsObj{
def Docs(s: List[String], b:Int): List[String] = { ... }
}
The second one is:
object Distance{
def tanimoto(l1: List[String], l2: List[String]): Float={
var list1= List[String]()
list1=DocsObj.Docs(l1,6).asInstanceOf[List].toSet
}
}
the error is the following one:
<console>:29: error: polymorphic expression cannot be instantiated to expected type;
found : [B >: String]scala.collection.immutable.Set[B]
required: List[String]
list1=DocsObj.Docs(list1,6).asInstanceOf[List[String]].toSet
The problem is that the value you are attempting to assign to
list1is aSet, but thelist1var is of typeList.The compiler error explains this as best it can, but perhaps the error message is a bit obscure because the right hand side of the assignment could take many types ("polymorphic expression"), so the "found" line in the error message is a range of types, rather than a single type.
Try either changing
list1to be of typeSet[String]or changing thetoSetcall to atoListcall.