This week's giveaway is in the Cloud/Virtualization forum. We're giving away four copies of Production-Ready Serverless (Operational Best Practices) and have Yan Cui on-line! See this thread for details.
On page 291 of Head First Java, they discuss autoboxing and specify that references can be assigned to either the wrapped objected or the primitive type. However, on the picture, they have a double reference defined with Integer and Int types being thrown in. Is this an error or have I misunderstood the concept?
Yan Digilov wrote:Ah, sorry yall, I am talking about the section ABOVE the sharpen your pencil piece. I mean the one titled "Assignment". It goes "Double d = x;" and there is an Integer and an int pointing to it...
I think taking a step to compile that simple line is not a big deal. Either it's an error or not, compiler is the best one which will tell you about it, it's one of the best core task assigned to it. but it's well likely for a compiler to not caught the errors which will really happen during run time as those are generated dynamically. in that case it's again not a following big step to run that program to be sure about the behaviour of code is, as i expected.
Now experiment the same code with a java as mentioned in the book and think about what really goes behind the scene?
1.) if not compiled, why really it didn't compile, what's wrong have you done there...
2.) if compiled but not ran, what's really something that compiler has not really caught. and the most important the error, why does it appear?
3.)if compiled and run successfully, why can i assign int to a Double reference. what really is going behind the scene? Is there any optimization added by compiler, if so then what are they.
Tell us your views first, then we will see if their are any problems.
Try to enjoy your work while doing it,it will Automatically convert in Hard Work...
posted 2 months ago
If you look through the Java® Language Specification, you will find that boxing conversion is possible, or widening conversion, but not both together. Please check the book's website and see whether any errors have been reported for that page.
No holds barred. And no bars holed. Except this tiny ad:
global solutions you can do in your home or backyard