This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
is not compiling because the method is waiting for two arguments of the same type. You give him an int and a Double. Note that integer litteral are considered like int. Thus 123 will be boxed as an Integer.
but I think the reason the original line is not compiling are not the parameters (123 is boxed as Integer) but the result, which is of class Number (common superclass of Integer and Double) and cannot be converted to double
this compiles ok:
Joined: Aug 11, 2007
Originally posted by Arek Orzechowski: Hi, .... this compiles ok:
I agree with you that the code will compile, because Number is superclass of Integer and Double. Since we are talking of compilation it's ok.
I will just add that the code will throw a ClassCastException if you don't turned 123 into a double even if it compiles.