title: Changing Return type of a function in Scala
body: <p>I need to write a function that has the return type <em>NodeSeq (scala.xml.NodeSeq)</em>,<br>
  In the below function, I'm trying to get the NodeSeq of an XML file, by evaluating an expression using the below code. The compiler throws type mismatch error.</p>
  
  <pre><code>import scala.reflect.runtime.universe
  
  def someFunc(params): NodeSeq = {
    some code
    ....
    val evaluator = universe.runtimeMirror(getClass.getClassLoader).mkToolBox()
    val data: NodeSeq = evaluator.eval(evaluator.parse(expression))  // return type - Any
  
    if(data.getClass.getName == scala.xml.NodeSeq) data else NodeSeq.Empty
  }
  </code></pre>
  
  <p>the <em>val data</em> should ideally contain NodeSeq (from the data I have), but I'm evaluating an expression, the return type of the expression can be anything, </p>
  
  <p>I understand, why I can't return NodeSeq using the above code,<br>
  the best I could come up with is the last <em>if</em> condition.<br>
  Is there anything, that I can do to change the return type of this function to NodeSeq from Any?</p>