Does using final for variables in Java improve garbage collection?
问题 Today my colleagues and me have a discussion about the usage of the final keyword in Java to improve the garbage collection. For example, if you write a method like: public Double doCalc(final Double value) { final Double maxWeight = 1000.0; final Double totalWeight = maxWeight * value; return totalWeight; } Declaring the variables in the method final would help the garbage collection to clean up the memory from the unused variables in the method after the method exits. Is this true? 回答1: