This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
firstly, please use code tags, it makes your code so much easier to read.
Anyway, Integer is the wrapper class for int. It is an object. double and int are primitive types. Hence when you pass 2.0 it invoked the method (double ival) as expected. When you pass 1, it does not match the (Integer ival) method as 1 is a primitive. 1 will fit into a double so it calls the (double ival) method instead. You should change the method signature to be
to get it to invoke it when
Alternatively, you could leave the method as it is and invoke it with
I assume this is using JDK1.4, as I assume in 5.0 autoboxing should kick in here and make the original example work as expected?