20

IntelliJ shows that OptionBuilder is deprecated in this example code from http://commons.apache.org/proper/commons-cli/usage.html.

What should I use as the replacement?

import org.apache.commons.cli.*;

Options options = new Options();
options.addOption(OptionBuilder.withLongOpt( "block-size" )
       .withDescription( "use SIZE-byte blocks" )
       .hasArg()
       .withArgName("SIZE")
       .create());
4

2 回答 2

29

来自http://commons.apache.org/proper/commons-cli/javadocs/api-release/index.html

已弃用。从 1.3 开始,改用 Option.builder(String)

这是替换:

Options options = new Options();
Option option = Option.builder("a")
    .longOpt( "block-size" )
    .desc( "use SIZE-byte blocks"  )
    .hasArg()
    .argName( "SIZE" )
    .build();
options.addOption( option );
于 2016-01-28T00:42:33.313 回答
2

使用(内部)类Option.Builder,如

Option option = Option.builder("a")
 .required(true)
 .longOpt("arg-name")
 .build();

参照。Option.Builder Java 文档。即返回的静态builder()方法和尾随调用给你一个.OptionOption.Builderbuild()Option

于 2016-01-28T00:39:58.420 回答