Scala: Method overloading over generic types

前端 未结 3 1343
夕颜
夕颜 2020-12-31 11:12

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;

publ         


        
3条回答
  •  滥情空心
    2020-12-31 11:43

    The Manifest won't really help either becuase those will have the same type after erasure.

    What will help having different numbers of arguments (or different types after erasure). I find having different numbers of implicit arguments can transparently solve this problem, and by using scala.Predef.DummyImplicit, you don't even have to import an implicit anywhere.

    class Test{
      def foo(ints : List[Int])
      def foo(doubles : List[Double])(implicit i1:DummyImplicit)
      def foo(strings : List[String])(implicit i1:DummyImplicit, i2:DummyImplicit)
    }
    

提交回复
热议问题