2013-04-17 20 views
7

Chciałbym zdefiniować klasę ContextItem jako rozszerzenie klasy java Predicate o cechę Confidence.Rozszerzanie klasy Java o cechę Scala

Zaufanie jest prostą cechą, która po prostu dodaje pole zaufania do tego, co rozszerza.

trait Confidence{ 
    def confidence:Double 
} 

jestem definiowania moje ContextItem klasę po prostu stwierdzając:

class ContextItem extends Predicate with Confidence{} 

Ale próbuje skompilować Daje ...

com/slug/berds/Berds.scala:11: error: overloaded method constructor Predicate with  alternatives: 
    (java.lang.String,<repeated...>[java.lang.String])com.Predicate <and> 
    (java.lang.String,<repeated...>[com.Symbol])com.Predicate <and> 
    (java.lang.String,java.util.ArrayList[com.Symbol])com.Predicate <and> 
    (com.Predicate)com.Predicate <and> 
    (com.Term)com.Predicate <and> 
    (java.lang.String)com.Predicate 
cannot be applied to() 
class ContextItem(pred:Predicate) extends Predicate with Confidence{ 
      ^

To wydaje się trywialny przykład, więc co się dzieje źle?

Predicate (co nie jest moje) wygląda następująco:

/** Representation of predicate logical form. */ 
public class Predicate extends Term implements Serializable { 
    public Predicate(String n) { 
     super(n); 
    } 
    public Predicate(Term t) { 
     super(t); 
    } 
    public Predicate(Predicate p) { 
     super((Term)p); 
    } 
    public Predicate(String n, ArrayList<Symbol> a) { 
     super(n, a); 
    } 
    public Predicate(String n, Symbol... a) { 
     super(n, a); 
    } 
    public Predicate(String n, String... a) { 
     super(n, a); 
    } 
    @Override 
    public Predicate copy() { 
     return new Predicate(this); 
    } 
} 

Ani Predicate ani żaden z jej przodków realizuje zaufanie.

+0

mogliśmy zobaczyć klasę 'Predicate'? Czy implementuje metodę "zaufania"? – Nick

Odpowiedz

6

Myślę, że wymienia wszystkich konstruktorów Predicate i informuje Cię, że nie używasz żadnego z nich. Wartością domyślną jest użycie konstruktora bez parametrów, który tutaj nie istnieje. Składnia zadzwonić na przykład super-konstruktor (String), byłoby

class ContextItem extends Predicate("something") with Confidence 

lub

class ContextItem(str: String) extends Predicate(str) with Confidence 

Ponadto, w tej chwili swój def confidence jest abstrakcyjny sposób, więc nie będzie kompilować, dopóki nie daj mu definicję. Jeśli ma cechę dodać pole zapisu confidence to jest to, co chcesz w zamian:

var confidence: Double = 0.0 
Powiązane problemy