0
votes

I have a problem using a Java interface in my Scala class. Here's the issue.

First, this is the simplified Java interface :

java.util.concurrent.TimeUnit;
import Message;

public interface JavaInterface {
   public Message get(int param1, Long param2, TimeUnit unit);
}

Then, I have a Scala class that tries to use this interface

java.util.concurrent.TimeUnit
import Message

class ScalaClass extends JavaInterface {
    def get(param1:Int, param2: Long, unit:TimeUnit):Message = {
         new Message("Just a test")
    }
}

But when it compiles, the Scala compiler keeps complaining that that get() function was not implemented in the ScalaClass :

class ScalaClass needs to be abstract, since: [error] it has 1 unimplemented members. [error] /** As seen from class ScalaClass, the missing signatures are as follows. [error] * For convenience, these are usable as stub implementations. [error] */ [error] def get(x$1: Int,x$2: Long,x$3: java.util.concurrent.TimeUnit):Message = ???

I suspect it might be because Scala doesn't like that Java int, but I have not been able to get this to work, does any one have any ideas?

Thank you IS

1

1 Answers

5
votes

The Int is fine

scala> classOf[Int]
res0: Class[Int] = int

but the Long is not

scala> classOf[Long]
res3: Class[Long] = long

Try with

def get(param1:Int, param2: java.lang.Long, unit:TimeUnit): Message =
  new Message("Just a test")