2010-06-29 99 views
1

我有下面的類:重載構造錯誤

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) 

/* ... */ 
} 

編譯器顯示我folloging錯誤:

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) 

回答

3

的多,像類型的形式參數的存在和使用缺省值的你主要構造函數使得模糊的正式構造函數參數是默認的,以及哪個分配了實際參數。

解決它的一種方法是在構造函數調用中使用命名參數賦值。

+0

此解決方案不起作用。 – barroco 2010-06-30 08:13:35

+0

@ isola009:你將不得不多說。你有什麼特別的嘗試。造成什麼錯誤? – 2010-06-30 13:00:29