Scala 编译 OptionBuilder 时出错

2023-12-02

我正在使用 Apache commons cli (1.2) 进行命令行解析。

我的代码中有以下内容:

import org.apache.commons.cli.OptionBuilder
OptionBuilder.withLongOpt("db-host").hasArg.
withDescription("Name of the database host").create('h')

我收到错误hasArg is not a member of org.apache.commons.cli.OptionBuilder。如果我改变也没有什么区别.hasArg to .hasArg().

Why?

顺便说一句,Java 解析得很好。


import org.apache.commons.cli.OptionBuilder
OptionBuilder.withLongOpt("db-host").hasArg.
withDescription("Name of the database host").create('h')

我收到错误hasArg is not a member of org.apache.commons.cli.OptionBuilder。如果我改变也没有什么区别.hasArg to .hasArg().

Why?

Because 没有实例方法hasArg in OptionBuilder,只有一个静态方法。自从hasArg是静态方法,显然您需要在类上调用它,而不是在类的实例上调用它。

顺便说一句,Java 解析得很好。

我不明白这与解析有什么关系。 Scala 也能很好地解析这个问题。另外,一些完全不同的编程对该代码执行或不执行的操作完全无关,因为这是 Scala 代码,而不是其他语言。

你需要做这样的事情:

import org.apache.commons.cli.OptionBuilder

OptionBuilder.withLongOpt("db-host")
OptionBuilder.hasArg
OptionBuilder.withDescription("Name of the database host")

val optionParser = OptionBuilder.create('h')
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Scala 编译 OptionBuilder 时出错 的相关文章

随机推荐