jcommander icon indicating copy to clipboard operation
jcommander copied to clipboard

Add support for adding classes, not only instances

Open JanecekPetr opened this issue 13 years ago • 0 comments

Sometimes, when working with static fields, it would be most convenient to be able to pass a class (SomeClass.class) to JCommander instead of an instance. Sometimes, instances aren't even possible to make (for abstract classes, for example).

The following code expresses my wish:

public class Tada {
    public static void main(String[] args) {
        new JCommander(One.class, args);
    }
}

class One {
    @Parameter(names = "-somename", description = "Ba dum - tss!")
    public static String someVariable;
}

There's no need to instantiate One and I don't really want to do it - it might have serious side-effects I need to avoid until the instance is really needed.

JanecekPetr avatar Jul 16 '12 18:07 JanecekPetr