In C# I can overload methods on generic type as shown in the example below:
// http://ideone.com/QVooD
using System;
using System.Collections.Generic;
public class Test {
public static void Foo(List<int> ints) {
Console.WriteLine("I just print");
}
public static void Foo(List<double> doubles) {
Console.WriteLine("I iterate over list and print it.");
foreach(var x in doubles)
Console.WriteLine(x);
}
public static void Main(string[] args) {
Foo(new List<int> {1, 2});
Foo(new List<double> {3.4, 1.2});
}
}
However if I try to do the same in Scala, it will raise a compile time error that List[Int] and List[Double] erase to the same type due to erasure. I heard Scala's Manifests can be used to work around this, but I don't know how. I didn't find anything helpful in the docs either.
So my question is: How do I use Manifests (or whatever else that works) to overload methods over generic types that erase to same type due to erasure?
Kinda hackish, and both methods need the same return type (here: Unit)...