I am beginning in scala and I need to contain a bunch of ints, and something other than a number
in a List
.
For example List(4,null)
or List(4,"STOPSTR")
.
How would I declare a variable of type
List[Int or String]
(Kind of)?Also, is it at all possible to declare a variable for a list that can only contain a certain string. E.g.
List[Int or String=="STOPSTR"]
and have it checked at compile time.
For the reasons of a challenge, I can only use Lists for this exercise, no classes, no maps, not even Arrays.