我正在尝试使用Scala中的java jcommander库。 Java JCommander类具有多个构造函数:

 public JCommander(Object object)
 public JCommander(Object object, ResourceBundle bundle, String... args)
 public JCommander(Object object, String... args)

我想调用第一个接受而不是变量的构造函数。我试过了:
jCommander = new JCommander(cmdLineArgs)

我得到错误:
error: ambiguous reference to overloaded definition,
both constructor JCommander in class JCommander of type (x$1: Any,x$2: <repeated...>[java.lang.String])com.beust.jcommander.JCommander
and  constructor JCommander in class JCommander of type (x$1: Any)com.beust.jcommander.JCommander
match argument types (com.lasic.CommandLineArgs) and expected result type com.beust.jcommander.JCommander
jCommander = new JCommander(cmdLineArgs)

我也尝试使用命名参数,但是得到了相同的结果:
jCommander = new JCommander(`object` = cmdLineArgs)

如何告诉Scala我要调用不包含varargs的构造函数?

我正在使用Scala 2.8.0。

最佳答案

抱歉,我现在意识到这是Java的已知互操作性问题。参见this questionthe ticket。我知道的唯一解决方法是创建一个小型Java类,以消除这些调用的歧义。

10-06 12:52