There is Either
in scala which allow a variable to have 2 types value.
val x: Either[String, Int] = Left("apple")
However, I want to have more than 2 types for variable x e.g. {String, Int, Double, List[String] }
.
e.g. val x:[type can be either String, Int, Double or List[String]]
//So that I can store either String, Int, Double, List[String] value in x.
Is there any way to achieve this?