Class Constants
- java.lang.Object
-
- ej.bon.Constants
-
public class Constants extends Object
This class provides access to compile-time constants. A constant is retrieved from its name, and is replaced by its value using the desiredgetXXXmethod depending on the expected type.The constant name must be resolved by the compiler as a String literal at the location where the
getXXXmethod is called. Constant Expressions are specified in section15.28 Constant Expressionsof the Java Language Specification.The following usages are allowed:
// Name is a String Literal boolean value = Constants.getBoolean("MyConstant")// Name is a Field Access to a static final field declaration // of type String, and initialized with a Constant Expression static final String MY_CONSTANT = "My" + "Constant"; boolean value = Constants.getBoolean(MY_CONSTANT)
The following usages are not allowed:// Name is a String Object boolean value = Constants.getBoolean(new String("MyConstant"))// Name is a Field Access to a static final field declaration // of type String, but not initialized with a Constant Expression static final String MY_CONSTANT = getMyConstantName(); boolean value = Constants.getBoolean(MY_CONSTANT)
-
-
Constructor Summary
Constructors Constructor Description Constants()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleangetBoolean(String name)Gets abooleanconstant.static bytegetByte(String name)Gets abyteconstant.static chargetChar(String name)Gets acharconstant.static Class<?>getClass(String name)Gets aClassconstant.static doublegetDouble(String name)Gets adoubleconstant.static floatgetFloat(String name)Gets afloatconstant.static intgetInt(String name)Gets anintconstant.static longgetLong(String name)Gets alongconstant.static shortgetShort(String name)Gets ashortconstant.static StringgetString(String name)Gets aStringconstant.
-
-
-
Method Detail
-
getBoolean
public static boolean getBoolean(String name)
Gets abooleanconstant.The constant is resolved to
trueif its value is equals to"true",falseif its value is equals to"false".- Parameters:
name- the constant name- Returns:
- the boolean constant
-
getByte
public static byte getByte(String name)
Gets abyteconstant.The constant is resolved to a
byteif its value is resolved to anintincluded into the range[-128,127].- Parameters:
name- the constant name- Returns:
- the byte constant
- See Also:
getInt(String)
-
getChar
public static char getChar(String name)
Gets acharconstant.The constant is resolved to a
charif its value is resolved to anintincluded into the range[0,65535].- Parameters:
name- the constant name- Returns:
- the char constant
- See Also:
getInt(String)
-
getShort
public static short getShort(String name)
Gets ashortconstant.The constant is resolved to a
shortif its value is resolved to anintincluded into the range[-32768,32767].- Parameters:
name- the constant name- Returns:
- the short constant
- See Also:
getInt(String)
-
getInt
public static int getInt(String name)
Gets anintconstant.The constant is resolved to an
intif itsStringvalue:- is a valid argument for
Integer.decode(String) - is an unsigned integer written in hexadecimal format such as
0xFFFFFFFF. In this latter case, the constant is resolved to-1.
- Parameters:
name- the constant name- Returns:
- the int constant
- is a valid argument for
-
getLong
public static long getLong(String name)
Gets alongconstant.The constant is resolved to a
longif itsStringvalue:- is a valid argument for
Long.decode(String) - if an unsigned long written in hexadecimal format such as
0xFFFFFFFFFFFFFFFF. In this latter case, the constant is resolved to-1.
- Parameters:
name- the constant name- Returns:
- the long constant
- is a valid argument for
-
getFloat
public static float getFloat(String name)
Gets afloatconstant.The constant is resolved to a
floatif its value can be loaded byFloat.valueOf(String).- Parameters:
name- the constant name- Returns:
- the float constant
-
getDouble
public static double getDouble(String name)
Gets adoubleconstant.The constant is resolved to a
doubleif its value can be loaded byDouble.valueOf(String).- Parameters:
name- the constant name- Returns:
- the short constant
-
getString
public static String getString(String name)
Gets aStringconstant.- Parameters:
name- the constant name- Returns:
- the String constant
-
-