I have a function unlist taking as first argument a list of any type:
def unlist(xs: List[Any], ys: List[Any]): List[Any] = ...
and I call this function on the first element of an external list, which may or may not be a list of lists. Thus, I first need to check if this head element is itself a list, in which case I can call my unlist function.
I do it with InsintanceOf method, like so:
...
if (xs.head.isInstanceOf[List[Any]]) unlist(xs.head, ys)
However, this does not compile because of a type mismatch on xs.head:
Error: type mismatch;
found : Any
required: List[Any]
What am I doing wrong?
P.S.: since many of you have suggested to avoid type Any , I have to specify that this is part of a coding exercise aiming at having a function as general as possible