2

I have read this, and it should solve my problem, but I still get a Confusing argument '(Class<?>[])null', unclear if a varargs or non-varargs call is desired warning here, in both cases:

public class MultiArgument<T, E> implements Argument {
    private final Argument[] args;
    private final Class<T> type;
    private final New<T, E> maker;

    public MultiArgument(E enclosingInstance, Class<T> type, Argument... args) throws NoSuchMethodException {
        this.type = type;
        this.args = args;
        this.maker = New.create(enclosingInstance, type,
                (Class<?>[]) (ArrayUtils.<Argument, Class<?>>transform(args, Argument::getReturnType))); // here
        New.create(null, null, (Class<?>[])null); // and even here.
    }
...
}

New.create:

public static <T, E> New<T, E> create(E enclosingInstance, Class<T> type, Class<?>... argTypes) throws NoSuchMethodException {
    return new New<>((Class<E>) enclosingInstance.getClass(), enclosingInstance, type, argTypes);
}

And the full New.java, just in case: http://pastebin.com/rtCVkiGX

Community
  • 1
  • 1
snowflake
  • 131
  • 10
  • Which tool gives this warning? I have never seen such a warning from the javac compiler itself. – Codebender Aug 19 '16 at 15:23
  • @Codebender IntelliJ IDEA – snowflake Aug 19 '16 at 15:23
  • I am not sure about were exectly you get the warning but I overcame similar ones by using new `new String[]{null}` instead of null. – c0der Aug 19 '16 at 15:37
  • @c0der I am getting it at the line that has `// and even here.`, on the line directly before that, I get a very similar warning: `Confusing argument '(Class>[]) (ArrayUtils.>transform(args, Argument::getReturnType))', unclear if a varargs call or non-varargs call is desired`. – snowflake Aug 19 '16 at 15:40
  • @c0der, `new String[]{null}` is not the same as `(String[]) null` which is what the OP seems to be doing and probably needs. – Codebender Aug 19 '16 at 15:43
  • @Codebender `new String[]{null}` is not proposed as a replacement to ` (String[]) null` but a solution to avoid the warming when trying to set null argument to `String...args`. In the OPs case `new Class[]{null}` might be a more appropriate example. – c0der Aug 19 '16 at 17:34

0 Answers0