Scala: Constructor taking either Seq or varargs

前端 未结 3 1245
鱼传尺愫
鱼传尺愫 2021-01-01 15:43

I am guessing that, for compatibility reasons, the type of vararg parameters Any* is Array[Any] - please correct this if I\'m wrong. However, this does not expl

3条回答
  •  悲&欢浪女
    2021-01-01 16:02

    No: actually, Any* is actually almost identical to Seq[Any], not to Array[Any].

    To disambiguate between the two, you can use the technique to add a dummy implicit parameter to make the signature different:

    class Api(api_url: String, params: Seq[(String, String)]) {
      def this(api_url: String, params: (String, String)*)(implicit d: DummyImplicit) =
        this(api_url, params)
    }
    

提交回复
热议问题