1 添加依赖

        <dependency>
            <groupId>org.openjdk.jol</groupId>
            <artifactId>jol-core</artifactId>
            <version>0.9</version>
        </dependency>    

 

2 查看对象的内存布局

public class JolTest {

    static class T{
        private int i = 10;
    }

    public static void main(String[] args) {
        T o = new T();
        String s = ClassLayout.parseInstance(o).toPrintable();
        System.out.println(s);
    }
}

 

3 执行结果