0

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 Answer 1

5

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")
Sign up to request clarification or add additional context in comments.

1 Comment

Alternatively, maybe the Java interface was supposed to have a long instead of Long?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.