4

次のような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単に本体がないことですが、エラーは、問題が varargs パラメーターの型であることを示唆しています。

4

1 に答える 1

1

ジャワ:

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)

これは、@TravisBrown のコメントと一致する Scala 2.10 です。

于 2013-01-15T23:50:35.570 に答える