Strange error when overriding java varargs method

179 views
Skip to first unread message

Fabio Cechinel Veronez

unread,
Jun 15, 2011, 10:04:09 AM6/15/11
to scala-user
Hello all,

I've got a strange error when overriding (in fact i'm implementing an
interface) a java varargs method. It is strange because it happens
only when using anonymous class and expliciting its result type. I'm
not sure what the error is and I could not found a similar error on
varargs related issues. Those are my files:

Java Interface:
[code]
public interface VarArgs {
public void method(String... s);
}
[/code]

Scala class:
[code]
class ScalaVarArgs extends VarArgs {
// -- no problem on overriding it using ordinary class
def method(s: String*) { println(s) }
}

object ScalaVarArgs {

def main(args: Array[String]) {
//[1] Ok - no problem using inferred type
val varArgs = new VarArgs {
def method(s: String*) { println(s) }
}
varArgs.method("1", "2")

//[2] Ok
val b: VarArgs = varArgs
b.method("1", "2")

//[3] Ok
(new ScalaVarArgs).method("1", "2")
(new ScalaVarArgs: VarArgs).method("1", "2")

//[4]
// Compiler error: object creation impossible, since method
method in trait VarArgs of type (s:
<repeated...>[java.lang.String])Unit is not defined
var tagged: VarArgs = new VarArgs {
def method(s: String*) { println(s) }
}
}
}
[/code]

Does anyone know why this error only arises on item [4] ? Am I doing
something wrong?

Thanks in advance.

--
Fabio Cechinel Veronez

Mirco Dotta

unread,
Jun 16, 2011, 8:05:12 AM6/16/11
to Fabio Cechinel Veronez, scala-user
Hi Fabio,

Really unexpected behavior, I believe this should be reported as a bug. Could you please
check if a bug describing this issue already exists (here: https://issues.scala-lang.org/secure/Dashboard.jspa),
and in case it doesn't open a new one.

Make sure to also provide the below example as a demonstration of the problem.


-- Mirco

Fabio Cechinel Veronez

unread,
Jun 22, 2011, 8:46:40 AM6/22/11
to Mirco Dotta, scala-user
Thx, i've created an issue for it: https://issues.scala-lang.org/browse/SI-4729

--
Fabio Cechinel Veronez

Reply all
Reply to author
Forward
0 new messages