Do Java 14 records actually save memory over a similar class declaration or are they more like syntactic sugar?
问题 I’m hoping that Java 14 records actually use less memory than a similar data class. Do they or is the memory usage the same? 回答1: To add to the basic analysis performed by @lugiorgi and a similar noticeable difference that I could come up with analyzing the byte code, is in the implementation of toString , equals and hashcode . On one hand, previously used class with overridden Object class APIs looking like public class City { private final Integer id; private final String name; // all-args,