1

JCommander中是否可以将带有注释的类保存jcommander.Parameter到文件中,以便可以创建新对象,使用@ 语法从文件中读取?

例如,如果我有注释类

class IndexerCommandLineParameters {
    @Parameter(names = { "-s", "--source" }, description = "Source file or directory of audio files (*.wav or *.mp3). MUST BE 16bit!", required=true)
    public String source;

    @Parameter(names = { "-d", "--destination" }, description = "Destination file or directory (type must match source type).", required=true)
    public String destination;

    @Parameter(names = { "-v", "--verbositiy" }, description = "Verbosity in stderr: 0 - print only file processing errors, 1 - print indexing progress")
    public int verbositiy=1;

    @Parameter(names = {"-f", "--force"}, description = "Force to reindex alredy indexed fiels")
    public boolean reindex = true;

    @Parameter(names = {"-h", "--help"}, description = "Force to reindex alredy indexed fiels", help = true)
    private boolean help;
}

和类初始化

IndexerCommandLineParameters p = new IndexerCommandLineParameters();
JCommander c=new JCommander(p);
c.parse("-s", "xxxxx","-d", "yyyyy");
p.verbositiy=2;

我想创建文件,其中包含类似

-s xxxxx -d yyyyy -v 3 -f

我知道我可以.toString()在每个类中创建或类似的东西,但我正在寻找更通用的东西,我不必向每个带注释的类添加一些代码。

4

0 回答 0