OCPJP6
yusuf Kaplan wrote:Faraz, thank you for your great answer. This summarizes many key features to remember for the exam, I guess
But Im still not convinced: In the code example above why didnt the compiler perform step 2p (byte -> long) and then w1 (long -> Long) ???
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
Andreas Svenkson wrote:
yusuf Kaplan wrote:Faraz, thank you for your great answer. This summarizes many key features to remember for the exam, I guess
But Im still not convinced: In the code example above why didnt the compiler perform step 2p (byte -> long) and then w1 (long -> Long) ???
It has to do with the rules of boxing and widening in general, I recommend checking out this post: https://coderanch.com/t/417622/java-programmer-SCJP/certification/Golden-Rules-widening-boxing-varargs
Bear in mind, it's not entirely complete. Can't remember exactly now, but there was something about rule #4 that I believe I found slightly "incomplete" in its description.
Java Language Specification wrote:5.2 Assignment Conversion
Assignment conversion occurs when the value of an expression is assigned (§15.26) to a variable: the type of the expression must be converted to the type of the variable. Assignment contexts allow the use of one of the following:
an identity conversion (§5.1.1) a widening primitive conversion (§5.1.2) a widening reference conversion (§5.1.5) a boxing conversion (§5.1.7) optionally followed by a widening reference conversion an unboxing conversion (§5.1.8) optionally followed by a widening primitive conversion.
If, after the conversions listed above have been applied, the resulting type is a raw type (§4.8), unchecked conversion (§5.1.9) may then be applied. It is a compile time error if the chain of conversions contains two parameterized types that are not not in the subtype relation.
http://plainoldjavaobject.blogspot.in
Lalit Mehra wrote:
you cannot widen and then box because a WRAPPER boxes a value of it's own type only
http://plainoldjavaobject.blogspot.in
Lalit Mehra wrote:
when the literal value goes beyond the actual limit of the type, "byte" here, the second statement complains the same thing ... required short, found byte
yusuf Kaplan wrote:
Are you sure? I think, the compiler just the first line?!?
http://plainoldjavaobject.blogspot.in
Those are the largest trousers in the world! Especially when next to this ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|