To avoid casting and capitalize on static input, you can either return a tuple (String, Int, Int) :
def getResult = ("one two", 23, 45) val res = getResult res._1 // the line // alternatively use the extractor val (line, row, _) = getResult // col is discarded line // the line row // the row
or use the case class for the result:
case class MyResult(line: String, row: Int, col: Int) def getResult = MyResult("one two", 23, 45) val res = getResult res.line
I would prefer the case class, because the fields have been named, and this is really only one line.
source share