Samar Bir wrote:
It is depicting a widen and box concept. My question is, this is integer by default. Will it widen to long and then Box it? I am confused why it is giving a compile time error?
Why it cannot be widened to double? I guess double has enough space to hold an int and then box to double?
You already answered the question in your original post.
Samar Bir wrote:
I am reading JLS to understand the method matching by the JVM. A compiler cant widen and box. Here is one example which is
giving compile time error.
The
Java Language Specification defines what is allowed in a method invocation conversion. And widening (implicitly) followed by boxing (via autoboxing) is not one of the allowable options.
So, the answer to why the compiler doesn't allow it. It is because it is defined that way by the JLS. As for why the JLS doesn't allow it -- well, that is probably going to be left to speculation, unless someone has some sort of knowledge (or know someone) who help create the JLS.
Henry