diff --git a/src/main/java/picocli/CommandLine.java b/src/main/java/picocli/CommandLine.java index 7b58d9d7b..20c529087 100644 --- a/src/main/java/picocli/CommandLine.java +++ b/src/main/java/picocli/CommandLine.java @@ -11879,13 +11879,14 @@ static class CommandUserObject implements IScope { private CommandUserObject(Object objectOrClass, IFactory factory) { this.factory = Assert.notNull(factory, "factory"); - type = objectOrClass == null ? null : objectOrClass.getClass(); - instance = objectOrClass; if (objectOrClass instanceof Class) { - type = (Class) objectOrClass; instance = null; - } else if (objectOrClass instanceof Method) { - type = null; // don't mix in options/positional params from outer class @Command + type = (Class) objectOrClass; + } else { + instance = objectOrClass; + type = objectOrClass == null || objectOrClass instanceof Method // don't mix in options/positional params from outer class @Command + ? null + : objectOrClass.getClass(); } } @Override public String toString() {