Scala错误编译OptionBuilder [英] Scala error compiling OptionBuilder

查看:97
本文介绍了Scala错误编译OptionBuilder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using Apache commons cli (1.2) for command line parsing.

我的代码中包含以下内容:

I have the following in my code:

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更改为.hasArg(),则没有区别.

I get the error hasArg is not a member of org.apache.commons.cli.OptionBuilder. It makes no difference if I change .hasArg to .hasArg().

为什么?

顺便说一句,Java很好地解决了这个问题.

BTW, Java parses this fine.

推荐答案

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更改为.hasArg(),则没有区别.

I get the error hasArg is not a member of org.apache.commons.cli.OptionBuilder. It makes no difference if I change .hasArg to .hasArg().

为什么?

因为 OptionBuilder中没有实例方法hasArg,所以只有静态方法.由于hasArg是静态方法,显然您需要在类上调用它,而不是在类的实例上调用它.

Because there is no instance method hasArg in OptionBuilder, only a static method. Since hasArg is a static method, you obviously need to call it on the class, not on an instance of the class.

顺便说一句,Java很好地解决了这个问题.

BTW, Java parses this fine.

我不知道这与解析有什么关系. Scala对此也进行了解析.另外,某些完全不同的编程对该代码执行或不执行的操作完全无关紧要,因为这是Scala代码,而不是其他某种语言.

I don't understand what this has to do with parsing. Scala parses this just fine, too. Plus, what some completely different programming does or doesn't do with this code is utterly irrelevant, since this is Scala code, not some other language.

您需要执行以下操作:

import org.apache.commons.cli.OptionBuilder

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

val optionParser = OptionBuilder.create('h')

这篇关于Scala错误编译OptionBuilder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆