This class represents a C/C++ union ; it works in the same
way as
Struct (sub-class) except that all members are mapped
to the same location in memory.
Here is an example of C union: [code]
union Number {
int asInt;
float asFloat;
char asString[12];
};[/code]
And its Java equivalent:[code]
public class Number extends Union {
Signed32 asInt = new Signed32();
Float32 asFloat = new Float32();
Utf8String asString = new Utf8String(12);
}[/code]
As for any
Struct , fields are directly accessible:[code]
Number num = new Number();
num.asInt.set(23);
num.asString.set("23"); // Null terminated (C compatible)
float f = num.asFloat.get();[/code]
author: Jean-Marie Dautelle version: 1.0, October 4, 2004 |