com.generationjava.lang
Class Constant

java.lang.Object
  |
  +--com.generationjava.lang.Constant
All Implemented Interfaces:
java.io.Serializable

public class Constant
extends java.lang.Object
implements java.io.Serializable

Used to signify a constant value. Most commonly expected to be used in an interface, passed to a method that takes type: Constant and tests by equality and not the .equals() method. The constant wraps an Object value, thus allowing the Constant to contain actual information and not just a new Object. It also adds typing information, so users of your code are forced to use your constant and not push their own magic number in. It is extendable, so the cosntant can contain more than just the one value. It's not an interface, allowing people to provide their own classes which are 'Constantable' as this does not fit the use of ==.

See Also:
Serialized Form

Constructor Summary
Constant()
          Empty constructor.
Constant(boolean b)
           
Constant(byte b)
           
Constant(char c)
           
Constant(double d)
           
Constant(float f)
           
Constant(int i)
           
Constant(long l)
           
Constant(java.lang.Object obj)
          Pass the value to be wrapped by this Constant.
Constant(short s)
           
 
Method Summary
 boolean booleanValue()
           
 byte byteValue()
           
 char charValue()
           
 boolean equals(java.lang.Object obj)
          This runs equals on the underlying Object.
 float floatValue()
           
 java.lang.Object getValue()
          Get the value that this Constant contains.
 int intValue()
           
 long longValue()
           
 short shortValue()
           
 java.lang.String toString()
          The toString of the wrapped object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Constant

public Constant()
Empty constructor. Uses itself as its value.


Constant

public Constant(java.lang.Object obj)
Pass the value to be wrapped by this Constant.


Constant

public Constant(boolean b)

Constant

public Constant(byte b)

Constant

public Constant(short s)

Constant

public Constant(int i)

Constant

public Constant(char c)

Constant

public Constant(long l)

Constant

public Constant(float f)

Constant

public Constant(double d)
Method Detail

getValue

public java.lang.Object getValue()
Get the value that this Constant contains.

Returns:
Object value being wrapped.

charValue

public char charValue()

intValue

public int intValue()

floatValue

public float floatValue()

longValue

public long longValue()

byteValue

public byte byteValue()

shortValue

public short shortValue()

booleanValue

public boolean booleanValue()

toString

public java.lang.String toString()
The toString of the wrapped object.

Overrides:
toString in class java.lang.Object
Returns:
String describing this Constant.

equals

public boolean equals(java.lang.Object obj)
This runs equals on the underlying Object. The idea of Constant was that you could use == to show equality, however, RMI completely blows this away. So use .equals() when RMI is involved.

Overrides:
equals in class java.lang.Object


Copyright © 2000-2003 OSJava. All Rights Reserved.