There are scala's Eitherthat allow a variable to have a value of type 2.
val x: Either[String, Int] = Left("apple")
However, I want to have more than two types for the variable x, for example. {String, Int, Double, List[String] }.
e.g. val x:[type can be either String, Int, Double or List[String]]
Is there any way to achieve this?
Ra Ka source
share