Documentation of 'javolution37.javolution.io.Union' Java class
Union
javolution37.javolution.io

Class Union



  • public abstract class Union
    extends Struct

    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:

         union Number {
             int   asInt;
             float asFloat;
             char  asString[12];
         };
    And its Java equivalent:
         public class Number extends Union {
             Signed32   asInt    = new Signed32();
             Float32    asFloat  = new Float32();
             Utf8String asString = new Utf8String(12);
         }
    As for any 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();
    • Constructor Detail

      • Union

        public Union()
        Default constructor.
    • Method Detail

      • isUnion

        public final boolean isUnion()
        Returns true.
        Overrides:
        isUnion in class Struct
        Returns:
        true
        See Also:
        Union

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.