2013-04-17 34 views
7

我想定义一个类ContextItem作为java类Predicate的扩展,其特征为Confidence使用Scala特性扩展Java类

置信度是一个简单的特征,它只是增加一个信心领域的任何延伸。

trait Confidence{ 
    def confidence:Double 
} 

我简单地陈述定义我ContextItem类:

class ContextItem extends Predicate with Confidence{} 

但试图编译这个收益率...

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{ 
      ^

这似乎是一个简单的例子,所以这是怎么回事错误?

谓词(这是不是我的)看起来像:

/** 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); 
    } 
} 

无论谓词或其任何祖先的实现充满信心。

+0

我们可以看到'Predicate'类?它是否实施了“信心”方法? – Nick

回答

6

我想这是列出Predicate的所有构造函数,并通知您,您没有使用它们中的任何一个。默认是使用无参数的构造函数,这里不存在。语法来调用,例如(String)超级构造函数,将

class ContextItem extends Predicate("something") with Confidence 

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

而且,此刻你def confidence是一个抽象方法,所以不会编译,直到你给它一个定义。如果你想要的性状添加一个可写confidence场那么这就是你想要的东西,而不是:

var confidence: Double = 0.0