2013-01-15 127 views
4

我已经在Java中定义的方法,如:如何覆盖Scala中的Java可变参数方法?

void foo(int x, Thing... things) 

我需要重写,在Scala中,但是这两种给出错误:

override def foo(x: Int, things: Thing*) 
override def foo(x: Int, things: Array[Thing]) 

的错误是指<repeated...>但我不知道那是什么。

更新

雪地...请不要介意。我在2.10.0,我错误键入了一些东西,没有方法体。然后我对这个错误信息感到困惑,这对我来说似乎仍然很奇怪。在SBT:

> compile 
[info] Compiling 1 Scala source to [...]/target/scala-2.10/classes... 
[error] [...]/src/main/scala/Translator.scala:41: class MyMethodVisitor needs to be abstract, since method visitTableSwitchInsn is not defined 
[error] (Note that org.objectweb.asm.Label* does not match <repeated...>[org.objectweb.asm.Label]) 
[error] class MyMethodVisitor extends MethodVisitor (Opcodes.ASM4) { 
[error]  ^

的问题是,我只是visitTableSwitchInsn缺乏身体,但错误表明问题是可变参数参数的类型。

+1

这看起来像你可能会看到[错误](https://issues.scala-lang.org/browse/SI-4729)在2.10中修复。如果你认为不行,你可以给你的版本号和更多的上下文吗? –

+0

谢谢。我在我的大脑中看到了一个错误,再加上一个令人困惑的错误信息(我已经添加到该问题中)。 –

回答

1

的Java:

package rrs.scribble; 

public 
class VA1 
{ 
    public int va1(int... ints) { 
     return ints.length; 
    } 
} 

斯卡拉:

package rrs.scribble 

class VA1S 
extends VA1 
{ 
    override 
    def va1(ints: Int*): Int = 
    ints.length * 2 
} 

SBT:

> ~compile 
[info] Compiling 1 Scala source and 1 Java source to …/scribble/target/scala-2.10/classes... 
[success] Total time: 4 s, completed Jan 15, 2013 3:48:14 PM 
1. Waiting for source changes... (press enter to interrupt) 

这是斯卡拉2.10,这与@ TravisBrown的评论一致。

+0

谢谢。当我休息后回来时,我看到了明显的代码错误。 :|我的方法简直缺乏一个机构。也许错误信息可能会更好。我更新了这个问题。 –