
引用一个apache提供的lucene工具包
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
<version>4.0.0</version>
</dependency>@Data
public class People {
private int id;
private String username;
private BigDecimal money;
private byte[] bytes = new byte[1024 * 1024]; // 这里1024*1024byte等于1m
public People() {
}
public static void main(String[] args) {
People people = new People();
long size = RamUsageEstimator.sizeOf(people);
String humanedSize = RamUsageEstimator.humanSizeOf(people);
System.out.println("size:" + size);
System.out.println("humanedSize:" + humanedSize);
}
}size:1048624
humanedSize:1 MB如果有任何疑问或建议,欢迎在评论区留言,我们将尽力解答。 感谢您的耐心阅读

public class BlogEnding {
public static void main(String[] args) {
encourageEngagement();
}
public static void encourageEngagement() {
System.out.println("🚀 感谢您阅读本文!如果您觉得有收获,请一键三连:点赞 ❤️️、转发 🔁、评论 💬,并加关注哦!");
}
}