开发者

implementing java interface with scala class - type issue

开发者 https://www.devze.com 2023-01-02 13:16 出处:网络
Why on earth won\'t this compile? Scala 2.8.0RC3: Java public interface X { void logClick(long ts, int cId, String s, double c);

Why on earth won't this compile? Scala 2.8.0RC3:

Java

public interface X {
    void logClick(long ts, int cId, String s, double c);
}

Scala

class Y extends X {
  def logClick(ts: Long, cId: Int,sid: java.lang.String,c: Double) : Unit = {
  ...
  }
}

Error

class Y needs to be abstract, since method logClick in trait X of type
(ts: Long,cId: Int,s: java.lang.String,c: Doub开发者_StackOverflow中文版le)Unit is not defined


You need to add override before the definition of logClick in class Y.

class Y extends X {
  override def logClick(ts: Long, cId: Int,sid: java.lang.String,c: Double) : Unit = {
  ...
  }
}


EDIT:

For the reason Daniel said below, you don't even need to add override before the method. Your code is right as it is.

0

精彩评论

暂无评论...
验证码 换一张
取 消