1

I was developing the below class and when I execute the below class I get the following result..

public class Confusing {    
    private Confusing(Object o) {
        System.out.println("Object");
    }

    private Confusing(double[] dArray) {
        System.out.println("double array");
    }

    public static void main(String[] args) {
        new Confusing(null);
        // new Confusing((Object)null);
    }
}

Output :-

double array

could you please explain why the outcome is of double array on console.

Tom
  • 26,212
  • 21
  • 100
  • 111
user2094103
  • 685
  • 3
  • 7
  • 14

2 Answers2

1
 Confusing(null) 

method call goes to the most specific method

and here its

private Confusing(double[] dArray)

as double[] reference is more specific than genericObject reference

exexzian
  • 7,782
  • 6
  • 41
  • 52
1

The most specific applicable overload is used.

In this case the most specific is double array thus you get "double array" as output

PermGenError
  • 45,977
  • 8
  • 87
  • 106