如何在 Scala 中消除具有 vararg 和不具有 vararg 的方法之间的歧义
我正在尝试使用Scala的java jcommander库。java JCommander 类具有多个构造函数:
public JCommander(Object object)
public JCommander(Object object, ResourceBundle bundle, String... args)
public JCommander(Object object, String... args)
我想调用第一个不带 varargs 的构造函数。我试过了:
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。