KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I know that type erasure makes them look equal, type-wise, at runtime, so that: class Bar { def foo[A](xs: A*) { xs.foreach(println) } def foo[A, B](xs: (A, B)*) { xs.foreach(x => println(x._1 + " - " + x._2)) } } gives the following compiler error: <console>:7: error: double definition: method foo:[A,B](xs: (A, B)*)Unit and method foo:[A](xs: A*)Unit at line 6 have same type after erasure: (xs: Seq)Unit def foo[A,B](xs: (A, B)*) { xs.foreach(x => println(x._1 + " - " + x._2) ) } ^ But is there a simple way to be able to write: bar.foo(1, 2, 3) bar.foo(1 -> 2, 3 -> 4) and having these call different overloaded versions of foo, without having to explicitly name them: bar.fooInts(1, 2, 3) bar.fooPairs(1 -> 2, 3 -> 4)
Tags (comma-separated)
Save Edits
Cancel