Size of empty Java String
问题 I heard a colleague say that I would pay "24 bytes" if I dropped a String member in a Java class, even if the String is empty. Is that accurate? Is it the same for Integer, Float, Double? (as opposed to int, float, double, which would be only 4, 4 and 8 bytes each). 回答1: You'll pay 4 or 8 bytes for the reference . Whether you'll pay for an extra object per instance of your "container" object depends on how you get your empty string. For example, if you use the literal "" then all the