The integer class has two static methods that look very similar. One is integer. getinteger (string), and the other is integer. valueof (string ). If you only look at the method name, it is easy to split the functional areas of the two methods, or let's take a look at the Java documentation.
Integer. getinteger (string) is used to obtain the integer of the system Attribute Based on the specified name. The first parameter is considered as the name of the system property. You can use
The system. getproperty (Java. Lang. String) method is accessed. The property value string is interpreted as an integer and returned as an integer representing the value. You can find detailed descriptions of possible numeric formats in the getproperty definition description.
Integer. valueof (string) is used to obtain the integer represented by a given string.
Let me see if I understand:
- The integer. valueof (string) method assumes that the string parameter represents a value and converts the value string to an integer. That is to say, integer. valueof ("123") gets an integer object whose value is 123.
- The integer. getinteger (string) method assumes that the string parameter is the name of a system attribute value, reads the system attribute, and converts the value of the system attribute into a number. That is to say, integer. getinteger ("12345") should be null (assuming there is no system attribute named 12345 ).
Although the functions of these two methods are different, they are not clearly distinguished from the method name, which is often confusing. There are many bugs because the valueof function is intended but the getinteger method is used incorrectly.
This is a bad example of ambiguity in the Java language. Another bad example is boolean. getboolean ("true "). The function of Boolean. getboolean (string) is similar to that of integer. getinteger (string. Generally, we do not have a system attribute named "true". Therefore, Boolean. getboolean ("true") usually returns Boolean. False. This is even worse than integer. getinteger (string). It is better to return a null value to make it easier to discover errors.