What happens if Var args method also exists with overloaded methods exists in a Java method

Here is a program with method overloading done.

package com.tests;
public class BasicClass {

    public void getMe(Object a) {
        System.out.println("getMe 1");
    }

    public void getMe(Object a, Object b) {
        System.out.println("getMe 2");
    }

    public void getMe(Object a, Object b, Object c) {
        System.out.println("getMe 3");
    }

    public void getMe(Object a, Object b, Object c, Object d) {
        System.out.println("getMe 4");
    }

    public void getMe(Object... parms) {
        System.out.println("getMe 5");
    }
}

What is the exact benefit do we get with this type of polymorphism..?

Jon Skeet
people
quotationmark

This is often done for optimization. It allows common operations (providing up to four values) to be performed without creating an array, whilst still giving the flexibility of allowing an arbitrary number of arguments.

To give a concrete, suppose we didn't have the first four overloads. In that case,

instance.getMe("a", "b");

would be converted by the compiler into:

instance.getMe(new Object[] { "a", "b" });

If the implementation doesn't need the arguments in an array, it's nice to avoid that array creation.

people

See more on this question at Stackoverflow