Can Java allocate a list on stack?
问题 Every time when I initiate a list in java, I will do List<Integer> list = new LinkedList<>(); I assume that this will allocate the list on heap. Wonder if there's anyway that I could allocate the list on stack? 回答1: All objects, including their individual attributes, are stored on the heap. All local variables, and their arguments, are stored on the stack because they contain primitive values or references. However, in special cases, the java virtual machine may perform escape analysis and