Strange error when overriding java varargs method

180 weergaven
Naar het eerste ongelezen bericht

Fabio Cechinel Veronez

ongelezen,
15 jun 2011, 10:04:0915-06-2011
aan 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

ongelezen,
16 jun 2011, 08:05:1216-06-2011
aan 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

ongelezen,
22 jun 2011, 08:46:4022-06-2011
aan Mirco Dotta, scala-user
Thx, i've created an issue for it: https://issues.scala-lang.org/browse/SI-4729

--
Fabio Cechinel Veronez

Allen beantwoorden
Auteur beantwoorden
Doorsturen
0 nieuwe berichten