scala coalesces multiple function call parameters into a Tuple -- can this be disabled?

Posted by landon9720 on Stack Overflow See other posts from Stack Overflow or by landon9720
Published on 2010-05-17T16:35:20Z Indexed on 2010/05/17 16:40 UTC
Read the original article Hit count: 126

Filed under:

This is a troublesome violation of type safety in my project, so I'm looking for a way to disable it. It seems that if a function takes an AnyRef (or a java.lang.Object), you can call the function with any combination of parameters, and Scala will coalesce the parameters into a Tuple object and invoke the function.

In my case the function isn't expecting a Tuple, and fails at runtime. I would expect this situation to be caught at compile time.

object WhyTuple {
 def main(args: Array[String]): Unit = {
  fooIt("foo", "bar")
 }
 def fooIt(o: AnyRef) {
  println(o.toString)
 }
}

Output:

(foo,bar)

© Stack Overflow or respective owner

Related posts about scala