Overview | Package | Class | Tree | Deprecated | Index | Help
| J avolution v5.3 (J2SE 1.5+)
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## javolution.io
Class Union

    java.lang.Object
      javolution.io.Struct
          javolution.io.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();

`

Version:
  1.0, October 4, 2004
Author:
  Jean-Marie Dautelle

Nested Class Summary

Nested classes/interfaces inherited from class javolution.io.Struct
`Struct.Bool, Struct.Enum16, Struct.Enum32, Struct.Enum64, Struct.Enum8, Struct.Float32, Struct.Float64, Struct.Member, 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`

Field Summary

Fields inherited from class javolution.io.Struct
`MAXIMUM_ALIGNMENT`

Constructor Summary
`Union()` Default constructor.

Method Summary
`boolean` | `isUnion()` Returns `true`.

Methods inherited from class javolution.io.Struct
`address, array, array, array, array, array, array, array, byteOrder, getByteBuffer, getByteBufferPosition, inner, isPacked, read, setByteBuffer, setByteBufferPosition, size, toString, write`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

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`

Overview | Package | Class | Tree | Deprecated | Index | Help
| J avolution v5.3 (J2SE 1.5+)
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2005 - 2009 Javolution.