Given following method:
Long getLong() {
...
}
If I call it and assign the return value to a variable like this:
long abc = getLong();
Will a Long object get generated and then converted to long or Java is smart enough to avoid generating the intermediate Long object? Or it might actually depends on the implementation of getLong()?
The reason I am asking this is that the wrapper object size is usually much bigger than the corresponding primitive type size. If I have to call this method a lot of times and each time memory needs to be allocated to the Long object, the program will end up consuming a lot more memory than it actually needs, which triggers more GC cycles.
Also, how can I verify the exactly steps happening when executing long abc = getLong() (basically also looking for guidance on how can I get answers myself for the questions above)?