Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overriding Java interface with overloaded vargs methods in Scala

Tags:

java

scala

Is there a way to implement the following Java interface in Scala?

public interface Request {
    void acceptLanguage(Locale... locales);
    void acceptLanguage(String... locales);
}

I tried:

override def acceptLanguage(locales: Locale*) : Unit =
override def acceptLanguage(locales: String*) : Unit =

But that gives me:

error: double definition:
have same type after erasure

And I tried this:

override def acceptLanguage(locales: Locale*) (implicit Manifest[Locale]) : Unit = {}
override def acceptLanguage(locales: String*) (implicit Manifest[String]): Unit = {}

But that gives a different signature so override fails

I am using version 2.9.2.

like image 581
Eduardo Avatar asked Nov 14 '12 23:11

Eduardo


1 Answers

Use @varargs annotation:

override def acceptLanguage(@varargs locales: Locale*) : Unit =
override def acceptLanguage(@varargs locales: String*) : Unit =
like image 187
ghik Avatar answered Sep 27 '22 23:09

ghik