Object parameter not accepting string

java

Solution

This is a variable-arity method:

public void errorNew(final int a, final String key, final Object... params);

and this is a fixed-arity method:

public void errorNew(final int a, final String key, final Object[] params);

A variable-arity method is applicable if the number of actual arguments is equal or greater to `n - 1`, where `n` is the number of parameters declared by the method. A fixed-arity method is only applicable if the number of arguments is exactly equal to the number of declared parameters (see the specs)

So the difference is not at the bytecode level, but at the compiler stage: when the compiler has to resolve the method signature, the algorithm changes as I described above, depending on the declaration being a fixed- or variable-arity one. That's why the compiler doesn't complain when your `LoggerImpl` implements the `Logger` interface using a vararg parameter, but can't find the method when you call it on an instance of the `Logger` interface (method signatures are resolved statically at compile-time, not dynamically at runtime, depending on the actual type of the object)

Problem

I have a method with following signature - ``` public void errorNew(final int a, final String key, final Object... params); ``` And I am trying to call it as - ``` errorNew(1, "a", "vb", "df"); ``` But eclipse is showing me error - ``` The method errorNew(int, String, Object[]) in the type Logger is not applicable for the arguments (int, String, String, String) ``` Any idea about the reason? When I try to build using maven, it shows following error - ``` method errorNew in interface Logger cannot be applied to given types; [ERROR] required: int,java.lang.String,java.lang.Object[] [ERROR] found: int,java.lang.String,java.lang.String,java.lang.String [ERROR] reason: actual and formal argument lists differ in length ```

Original source