I do not understand who you are. Using 1.8, from Netbeans:
public static class C1 {
boolean a,b,c,d;
}
public static class C2 {
boolean a,b,c,d,e;
}
public static void main(String[] args) {
try {
Constructor<Unsafe> unsafeConstructor = Unsafe.class.getDeclaredConstructor();
unsafeConstructor.setAccessible(true);
Unsafe unsafe = unsafeConstructor.newInstance();
String[] fieldNames = new String[] {"a","b","c","d"};
for (String fieldName : fieldNames) {
System.out.println(fieldName+": "+unsafe.objectFieldOffset(C1.class.getDeclaredField(fieldName)));
}
}
catch(Exception e) {
e.printStackTrace();
}
}
gives the result
a: 12
b: 13
c: 14
d: 15
... which indicates that each Boolean value occupies a separate byte offset in the object. The header is 12 bytes.
source
share