A DESCRIPTION OF THE REQUEST :
Add a static constant named EMPTY_STRING that references an empty String to the java.lang.String class.
JUSTIFICATION :
Where I work, we frequently test for the empty String or initialize String values to it. We are encouraged to avoid the use of literals in favor of named constants, so on multiple programs we have created EMPTY_STRING constants which identify the empty String. It would be very convenient to have a static constant in String that represented the empty String. Also the normal empty String ("") can be very hard to read when mixed in with many other quoted Strings.
This would make checks such as the following more explicit:
if ((aString != null) && !aString.equals(String.EMPTY_STRING))
{
// DO SOMETHING
}
else
{
// HANDLE INVALID INPUT
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A static constant named EMPTY_STRING in the java.lang.String class that represents the empty String.
ACTUAL -
A static constant named EMPTY_STRING in the java.lang.String class that represents the empty String.
---------- BEGIN SOURCE ----------
assertEquals("", String.EMPTY_STRING);
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
The workaround is simply to use "" for the empty String. The use of a named constant would be beneficial for explicit checks or initialization.
Add a static constant named EMPTY_STRING that references an empty String to the java.lang.String class.
JUSTIFICATION :
Where I work, we frequently test for the empty String or initialize String values to it. We are encouraged to avoid the use of literals in favor of named constants, so on multiple programs we have created EMPTY_STRING constants which identify the empty String. It would be very convenient to have a static constant in String that represented the empty String. Also the normal empty String ("") can be very hard to read when mixed in with many other quoted Strings.
This would make checks such as the following more explicit:
if ((aString != null) && !aString.equals(String.EMPTY_STRING))
{
// DO SOMETHING
}
else
{
// HANDLE INVALID INPUT
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A static constant named EMPTY_STRING in the java.lang.String class that represents the empty String.
ACTUAL -
A static constant named EMPTY_STRING in the java.lang.String class that represents the empty String.
---------- BEGIN SOURCE ----------
assertEquals("", String.EMPTY_STRING);
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
The workaround is simply to use "" for the empty String. The use of a named constant would be beneficial for explicit checks or initialization.
- relates to
-
JDK-5047879 (str) String.EMPTY_STRING_ARRAY constant
-
- Closed
-