如何将空参数传递给Netbeans。

huangapple go评论63阅读模式
英文:

How to pass empty args to Netbeans

问题

我尝试在Netbeans Java项目中使用Properties-->Run-->Arguments传递空白命令行参数,使用""或''但没有效果。我有一些参数有时必须为空或null。

英文:

I tried to pass blank command line arguments in a Netbeans Java project using Properties-->Run-->Arguments with "" or '' but nothing.
I have some arguments that some times have to be empty or null.

答案1

得分: 2

处理这种情况的常见方式是在参数为空或空白时不指定参数。在CLI/脚本世界中,这是相当常见的做法。未指定的参数意味着要么使用默认值,要么没有值。

此外,还有一些Java的良好库可帮助您解析程序的options或参数,例如:


编辑

附加说明:

  • 如果没有更智能的选项/参数解析器,就无法正确处理空参数(即仅通过设置空白、空格或带引号的空字符串来处理)。要实现这一点的唯一方法是定义一个关键字或特殊字符,以便在处理args[]时识别空/未指定的参数。
  • 这种行为与Netbeans无关。它与Java如何解析命令行的main()方法的varargs相关。

有趣的链接:

英文:

The common way to handle that is to not specify arguments when they are blank or empty. It is quite the norm in the CLI/scripting world to work like this. Unspecified arguments mean either to use the defaults or no value.

Aside there are Java nice libraries to help you parse your program options or arguments, such as:


EDIT

Additonal remarks:

  • Without a smarter options/arguments parser, it is not possible to handle empty arguments properly (i.e. just by setting a blank, whitespace or quoted empty string). The only way to achieve that would be to define a keyword or special character in order to identify empty/unspecified arguments when processing args[].
  • This behavior is not bound to Netbeans. Rather it relates to how Java parses the varargs of the main() method from the command-line.

Interesting links:

huangapple
  • 本文由 发表于 2020年8月5日 23:12:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/63268192.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定