Ganesh Gowtham wrote:
How the method mtd() is called autoboxing happends automatically ? , why not for this num(primitive) and num(wrapper) and confusion wont happend ?
Put yourself in the place of the compiler. In the case of the mtd() method, you only have one option, and the only way to get to Integer, when given an int is to autobox. In the case of num(), you have two options, and two perfect matches. Why bother looking into the option of boxing when you have a perfect match?
Or to answer your question... the compiler just doesn't try everything. It has an order, and have ways to resolve ambiguous issues too.
Integer.valueOf(): Returns an Integer instance representing the specified int
value. If a new Integer instance is not required, this method should generally
be used in preference to the constructor Integer(int), as this method is likely
to yield significantly better space and time performance by caching frequently
But this leads to the question, when would a second Integer instance be
needed to represent 6? Would this be never?