0

I was experimenting with Method overloading and i came across this puzzling scenario:

class Dims {

void checkThis(long s) {System.out.println("long");}
void checkThis(int s) {System.out.println("int");}
void checkThis(long... s) {System.out.println("longs...");}
void checkThis(int... s) {System.out.println("ints...");}

public static void main(String[] args) {

    Dims d = new Dims();
    d.checkThis(45); // Prints int
    d.checkThis(43,45); // Error: The method checkThis(long[]) is ambiguous for the type Dims
} 

}

The compiler throws an error at the last line saying that it can't figure out which method to call, i couldn't figure out why? Please help.

user1307895
  • 39
  • 1
  • 2

0 Answers0