[email protected]
Java 15 - Foreign Memory Access
● Unions in Java
// A real number in 64 bits.
ValueLayout real = MemoryLayout.ofValueBits(64, ByteOrder.BIG_ENDIAN);
// Struct.
GroupLayout complex = MemoryLayout.ofStruct(real.withName("x"),
real.withName("y"));
GroupLayout polar = MemoryLayout.ofStruct(real.withName("rho"),
real.withName("theta"));
// Union.
GroupLayout coords = MemoryLayout.ofUnion(complex.withName("complex"),
polar.withName("polar"));