Forums Register Login

autoboxing and unboxing

+Pie Number of slices to send: Send
Hi guys, i was wondering since these statement are valid:


is it because the first one unbox a Short wrap object to a short and the second one autoboxes a byte into a byte object?
I mean what seems strange to me is that we're effectively assigning an object to a primitive and a primitive to an object
thanks
+Pie Number of slices to send: Send
Yes, auto boxing/unboxing is what that code demonstrates.
+Pie Number of slices to send: Send
Yes, and yes.
+Pie Number of slices to send: Send
compiler will do a job of autoboxing and unboxing during compilation.so even if you assign a primitive to its object equivalent reference,compiler will wrap that primitive and then assign it to that reference.
+Pie Number of slices to send: Send
There is more information in the Java™ Tutorials and the Java® Language Specification (=JLS). Beware: the JLS can be difficult to read.
Yeast devil! Back to the oven that baked you! And take this tiny ad too:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 235 times.
Similar Threads
Declaring s Short object
Why Byte boxing doesn't work here
S&B 1.5 Chapter 6, Question 4 explanation D
Working with byte variables
who will use wrap & un-wrap method now ?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 09:12:46.