Can someone help me by throwing some light on the below code examples
I am refering to 2 programs related to Overloading and use of varargs.
The below code throws an compile error since 2 methods have same syntax with concept of boxing in. I am ok with this.
class etattva105 {
public static void check(Double d1, Double ... d2) {
System.out.println("Double , Var-Args");
}
public static void check(Double d1, Double d2, Double ... d3) {
System.out.println("Double , Double , Var-args");
}
public static void check(double d1, Double d2, Double ... d3) {
System.out.println("double , Double , Var-args");
}
public static void main(
String [] args) {
check(12.3, 21.9, 37.7); // line 1
Here comes second prg.
The below code compiles fine and displays "Integer,Integer is called".
Similar to above prg, I expected this prg also to throw a compile error, but it goes fine. Can some one explain?
public class etattva10 {
public static void main(String[] args) {
int i = 10;
int k = 20;
method(i,k);
}
static void method(Integer... i){
System.out.println("Integer varargs is called");
}
static void method(Integer i,Integer j){
System.out.println("Integer,Integer is called");
}
static void method(int... i){
System.out.println("int varargs is called");
}
}