Please note that only order of the parameters are changed in below example. So my question is - Can we call below example is of method overloading?
public void show(String s, int a){
System.out.println("Test.show(String, int)");
}
public void show(int s, String a){
System.out.println("Test.show(int, String)");
}
Method overloading can be done by changing: The number of parameters in two methods. The data types of the parameters of methods. The Order of the parameters of methods.
The order of the parameters make a difference because it is a different signature. Imagine you had a human signature and altered the order of the letters, it would no longer be the same signature.
Method overloading means two or more methods have the same name but have different parameter lists: either a different number of parameters or different types of parameters. When a method is called, the corresponding method is invoked by matching the arguments in the call to the parameter lists of the methods.
Answer. No, the order of query parameters should not matter.
Yes, that's absolutely method overloading.
From section 8.4.9 of the JLS:
If two methods of a class (whether both declared in the same class, or both inherited by a class, or one declared and one inherited) have the same name but signatures that are not override-equivalent, then the method name is said to be overloaded.
"Override-equivalent" is described in section 8.4.2:
Two methods have the same signature if they have the same name and argument types.
[ ... Details on "same argument types ... ]
The signature of a method m1 is a subsignature of the signature of a method m2 if either:
m2 has the same signature as m1, or
the signature of m1 is the same as the erasure (§4.6) of the signature of m2.
Two method signatures m1 and m2 are override-equivalent iff either m1 is a subsignature of m2 or m2 is a subsignature of m1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With