Variable arity with different types

Skip to first unread message

Brendan Robert

Sep 25, 2017, 12:11:09 PM9/25/17
to jcommander
Hey guys I have a quick question. I am attempting to include a parameter that should allow one or two arguments and i would like the first argument to be a string and the second to be boolean. How can I model my Args object to allow for a number of inputs that look like the following:

-v strA true      -v strB

and i would like to see that I have two of these -v objects in a list with the first one as true and the second one as not specified so resort to whatever my default would be. At the end of the day the strings are going to be class names that will be instantiated through reflection and the optional boolean flag would point to additional program specifics for that class. Im used to only doing a single -v strA strB and a single --submit flag to provide the optional detail for all strings but i want the ability to capture for each string. Thanks! 

Cédric Beust ♔

Sep 25, 2017, 12:13:09 PM9/25/17
to jcommander
Make your parameter a list of objects and you'll have to perform some manual scanning to determine which argument is what.


You received this message because you are subscribed to the Google Groups "jcommander" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
For more options, visit

Reply all
Reply to author
0 new messages