Implement java interface with scala class problem

Why not compile it? 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 = { ... } } 

Mistake

 class Y needs to be abstract, since method logClick in trait X of type (ts: Long,cId: Int,s: java.lang.String,c: Double)Unit is not defined 
+6
scala
source share
1 answer

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 = { ... } } 

Strike>
EDIT:

For the reason Daniel mentioned below, you don’t even need to add an override before this method. Your code is right as it is.

+2
source share

All Articles