2

My function must take a list of values as argument, convert each one to string and add them to a list. The values can be either String, Int or Boolean.

How to define a function with the flexibility to handle the different types? Here is my initial function but as expected when i give int as argument, i get an type mismatch error

def test (s: String*): List[String] = {
  s.toList
}
Andrey Tyukin
  • 43,673
  • 4
  • 57
  • 93
djohon
  • 705
  • 2
  • 10
  • 25
  • Possible duplicate of [How can Scala receive multiple parameters in a method definition?](https://stackoverflow.com/questions/1438762/how-can-scala-receive-multiple-parameters-in-a-method-definition) – joel Jul 25 '18 at 11:51

1 Answers1

4
def test(s: Any*): List[String] = s.map(_.toString).toList
Andrey Tyukin
  • 43,673
  • 4
  • 57
  • 93