Class Union
- java.lang.Object
-
- javolution37.javolution.io.Struct
-
- javolution37.javolution.io.Union
-
public abstract class Union extends Struct
This class represents a
C/C++ union; it works in the same way asStruct(sub-class) except that all members are mapped to the same location in memory.Here is an example of C union:
And its Java equivalent:union Number { int asInt; float asFloat; char asString[12]; };As for anypublic class Number extends Union { Signed32 asInt = new Signed32(); Float32 asFloat = new Float32(); Utf8String asString = new Utf8String(12); }Struct, fields are directly accessible:Number num = new Number(); num.asInt.set(23); num.asString.set("23"); // Null terminated (C compatible) float f = num.asFloat.get();
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class javolution37.javolution.io.Struct
Struct.Bool, Struct.Enum16, Struct.Enum32, Struct.Enum64, Struct.Enum8, Struct.Float32, Struct.Float64, Struct.Reference32<S extends Struct>, Struct.Reference64<S extends Struct>, Struct.Signed16, Struct.Signed32, Struct.Signed64, Struct.Signed8, Struct.Unsigned16, Struct.Unsigned32, Struct.Unsigned8, Struct.Utf8String
-
-
Constructor Summary
Constructors Constructor and Description Union()Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description booleanisUnion()Returnstrue.-
Methods inherited from class javolution37.javolution.io.Struct
address, byteOrder, getByteBuffer, getByteBufferPosition, isPacked, read, setByteBuffer, setByteBufferPosition, size, toString, write
-
-
DMelt 3.0 © DataMelt by jWork.ORG