【问题标题】:Overloaded constructor error重载构造函数错误
【发布时间】:2010-06-29 16:14:42
【问题描述】:

我有以下课程:

class Step(kind:TipoStep.Value,
           message:String = "",
           study:List[Formula] = List(),
           lastAdd:Set[Formula] = Set(),
           lastDel:Set[Formula] = Set(),
           add:List[Formula] = List(),
           del:List[Formula] = List()
           ) {

  def this(step:Step,
           kind:TipoStep.Value,
           message:String = "",
           study:List[Formula] = List(),
           lastAdd:Set[Formula] = Set(),
           lastDel:Set[Formula] = Set()) = this(kind, message, study, lastAdd, lastDel, step.getAllAdd, step.getAllDel)

 /* ... */
}

编译器显示以下错误:

error: ambiguous reference to overloaded definition,
both method init$default$5 in object Step of type => scala.collection.mutable.Set[org.lorea.pltl.formula.Formula]
and  method init$default$5 in object Step of type => scala.collection.mutable.Set[org.lorea.pltl.formula.Formula]
match expected type scala.collection.mutable.Set[org.lorea.pltl.formula.Formula]
step = new Step(TipoStep.R_fixpoint, s, List(c1, c2), news)

【问题讨论】:

    标签: scala constructor overloading


    【解决方案1】:

    在您的主构造函数中存在多个类似类型的形式参数以及使用默认值,这使得哪个形式构造函数参数被默认以及哪个实际参数被分配变得不明确。

    解决它的一种方法是在构造函数调用中使用命名参数赋值。

    【讨论】:

    • @isola009:您将不得不说更多。你具体尝试了什么。结果是什么错误?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多