Primitives reappear, breaking the rules that I learned earlier. Well, not technically primitive, but made up of them.
I found out that whenever there is no method more specific than resting, a compile-time error occurs, as happens here.
public static void caller(){
z5();
z5(null);
}
public static void z5(Integer...integers){
System.out.println("Integer z5 called");
}
public static void z5(String...strings){
System.out.println("String z5 called");
}
Now primitives appear in the picture.
public static void caller(){
z1(null);
z1();
}
public static void z1(int...integers){
System.out.println("int z1 called");
}
public static void z1(long...longs){
System.out.println("long z1 called");
}
public static void z1(float...floats){
System.out.println("float z1 called");
}
Compilation time errors are expected here.
public static void caller(){
z1(null);
z1();
}
public static void z1(int...integers){
System.out.println("int z1 called");
}
public static void z1(boolean...bools){
System.out.println("bool z1 called");
}
Now my question is: int [], float [] or any array of primitives are not primitive types. Why are they handled differently than other reference types?
- UPDATE -
@ john16384 You don’t think I read your “Possible duplicate” of Varargs in method overloading in Java
var-args . , , OP , jdk 7.
, (int... is) (float... fs), (Integer... is) (Float...fs), (int... is) (boolean... bool)