jcommander 解析boolean参数

boolean类型有点特殊,后面不需要跟一个值,输入-local之后,local值即为true:

@Parameter(names = { "-local"}, description = "Local model, default cluster Model.")
public static boolean LOCAL_MODE = false;

如果一个boolean变量的默认值为true,而想通过参数设置为false,可以指定元数:

@Parameter(names = { "-log", "-verbose"}, description = " Wheather to write system log.", arity = 1)
public static boolean LOG = true;
原文地址:https://www.cnblogs.com/brainstorm/p/8386474.html