【发布时间】:2014-01-13 21:06:42
【问题描述】:
我有一段 Scala 代码:
class A {
def main(args: Array[String])
}
然后一段Java代码:
class B {
public static int test(final String... args) {
System.out.println("This is a test.");
// Use the arguments
...
}
}
我想要的是在 A.main 中调用 B.test,如下所示:
class A {
def main(args: Array[String]) = {
val result = B.test(args)
}
}
上面的代码不能工作,因为类型不匹配。如果有人能提供一个优雅的解决方案,我们将不胜感激。
请仅更改 Scala 部分,因为 Java 部分将来自另一个库。谢谢!
【问题讨论】:
-
我手头没有repl 可以验证,但我认为
B.test(args:_*)应该可以工作。 -
@folone 是的,就是这样!
-
我刚刚测试过,它有效。谢谢!
-
@folone 您应该将其发布为答案,以便可以关闭问题
-
@0__ 对,做到了。
标签: java scala command-line-arguments