Forums Register Login

Autoboxing

+Pie Number of slices to send: Send
hi,

Acc to my understanding, all primtives stay in stack, and objects stay in heap.Now, i want to know that how does int primitive is converted into Integer object in autoboxing. (i.e how does it get a reference to a stack and creates an object in the heap ). This was asked in one of the interviews which was attended by me ... Probabaly he wanted to know how does auutoboxing occurs internally

Also, he asked how can one improve/increase stack/heap memory programitaclly
+Pie Number of slices to send: Send
Internally Integer.valueOf is used for autoboxing.

+Pie Number of slices to send: Send
 

final int j = 5;



I would like to know how does it get reference of j, which resides in stack memory and then store it in heap. I would like to know w.r.t where it is stored etc i.e (Heap, Stack)...hope my question is clear
+Pie Number of slices to send: Send
 

Maan Suraj wrote:

final int j = 5;



I would like to know how does it get reference of j, which resides in stack memory and then store it in heap. I would like to know w.r.t where it is stored etc i.e (Heap, Stack)...hope my question is clear




Autoboxing doesn't occur with the code that you shown.

Henry
+Pie Number of slices to send: Send
Assuming that he meant the other line. It doesn't get a reference of j. It gets it's value.
+Pie Number of slices to send: Send
Thanks wouter.... I meant the other line itself... :-)

so what i understand form your post is that , it reads the value from the primitive, create a new object, with the value as in primitive and stores it in a heap. Right?

Thanks Again
+Pie Number of slices to send: Send
Yes that is correct.
Do you pee on your compost? Does this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 915 times.
Similar Threads
Reference Variables on the stack
on STACK or on HEAP?
What is heap & stack memory?
gc from msterexam
Stack & heap for Static methods
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 18:02:56.