原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/14985105.html
Maven Depedency
... <dependencies> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.20</version> </dependency> <dependency> <groupId>org.openjdk.jol</groupId> <artifactId>jol-core</artifactId> <version>0.16</version> </dependency> </dependencies> ...
SRC
package org.fool.test; import lombok.Data; import org.openjdk.jol.info.ClassLayout; import java.math.BigDecimal; import java.math.BigInteger; @Data public class JolTest { private byte b; private boolean flag; private char c; private int i; private float f; private double d; private long l; private Byte wrapperB; private Boolean wrapperFlag; private Character wrapperC; private Integer wrapperI; private Float wrapperF; private Double wrapperD; private Long wrapperL; private BigInteger bigInteger; private BigDecimal bigDecimal; private String str; private Object object; public static void main(String[] args) { JolTest jolTest = new JolTest(); jolTest.setB((byte) 1); jolTest.setFlag(true); jolTest.setC('a'); jolTest.setI(1); jolTest.setF(2f); jolTest.setD(3.0); jolTest.setL(4L); jolTest.setWrapperB(new Byte("1")); jolTest.setWrapperFlag(new Boolean(false)); jolTest.setWrapperC(new Character('c')); jolTest.setWrapperI(new Integer(1)); jolTest.setWrapperF(new Float(2)); jolTest.setWrapperD(new Double(3.0)); jolTest.setWrapperL(new Long(4)); jolTest.setBigInteger(new BigInteger("100000000000")); jolTest.setBigDecimal(new BigDecimal("999999999999.999")); jolTest.setStr("string"); jolTest.setObject(new Object()); System.out.println(ClassLayout.parseInstance(jolTest).toPrintable()); } }
Console Output
Reference
https://segmentfault.com/a/1190000012354736
欢迎点赞关注和收藏