public class Constants extends Object
getXXX
method depending on the expected type.
The constant name must be resolved by the compiler as a String literal at the
location where the getXXX
method is called. Constant Expressions
are specified in section 15.28 Constant Expressions
of 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)
Modifier and Type | Method and Description |
---|---|
static boolean |
getBoolean(String name)
Gets a
boolean constant. |
static byte |
getByte(String name)
Gets a
byte constant. |
static char |
getChar(String name)
Gets a
char constant. |
static Class<?> |
getClass(String name)
Gets a
Class constant. |
static double |
getDouble(String name)
Gets a
double constant. |
static float |
getFloat(String name)
Gets a
float constant. |
static int |
getInt(String name)
Gets an
int constant. |
static long |
getLong(String name)
Gets a
long constant. |
static short |
getShort(String name)
Gets a
short constant. |
static String |
getString(String name)
Gets a
String constant. |
public static boolean getBoolean(String name)
boolean
constant.
The constant is resolved to true
if its value is equals to
"true"
, false
if its value is equals to
"false"
.
name
- the constant namepublic static byte getByte(String name)
byte
constant.
The constant is resolved to a byte
if its value is resolved to
an int
included into the range [-128,127]
.
name
- the constant namegetInt(String)
public static char getChar(String name)
char
constant.
The constant is resolved to a char
if its value is resolved to
an int
included into the range [0,65535]
.
name
- the constant namegetInt(String)
public static short getShort(String name)
short
constant.
The constant is resolved to a short
if its value is resolved to
an int
included into the range [-32768,32767]
.
name
- the constant namegetInt(String)
public static int getInt(String name)
int
constant.
The constant is resolved to an int
if its String
value:
Integer.decode(String)
0xFFFFFFFF
. In this latter case, the constant is resolved to
-1
.name
- the constant namepublic static long getLong(String name)
long
constant.
The constant is resolved to a long
if its String
value:
Long.decode(String)
0xFFFFFFFFFFFFFFFF
. In this latter case, the constant is
resolved to -1
.name
- the constant namepublic static float getFloat(String name)
float
constant.
The constant is resolved to a float
if its value can be loaded
by Float.valueOf(String)
.
name
- the constant namepublic static double getDouble(String name)
double
constant.
The constant is resolved to a double
if its value can be loaded
by Double.valueOf(String)
.
name
- the constant namepublic static String getString(String name)
String
constant.name
- the constant name