I’d like to define a method accepting varargs, so that I get the types with which it was called even in the case of nulls.
def foo(args: Any*) = ....
val s: String = null
foo(1, s) // i'd like to be able to tell in foo that args(0) is Int, args(1) is String
In terms of the original question, I’m pretty sure it’s not possible.
Without knowing exactly what you’re trying to achieve (ie, why it must be a variable-length list of arbitrary types), it is difficult to offer an alternative. However, there are two things that came to my mind when I read the question that may be an option for you: Default argument values in combination with named arguments (requires Scala 2.8+), and the
HListdata type (less likely).