区分下
Long.getLong
和
Long.parseLong
二者的JavaDoc如下:
getLong的:取系统参数的~
Determines the long
value of the system property with the specified name.
The first argument is treated as the name of a system property. System properties are accessible through the java.lang.System.getProperty(java.lang.String)
method. The string value of this property is then interpreted as a long
value and a Long
object representing this value is returned. Details of possible numeric formats can be found with the definition of getProperty
.
If there is no property with the specified name, if the specified name is empty or null
, or if the property does not have the correct numeric format, then null
is returned.
parseLong的:真正把字符串解析成为Long对象的,如果格式错误则抛出NumberFormat异常!
Parses the string argument as a signed decimal long
. The characters in the string must all be decimal digits, except that the first character may be an ASCII minus sign '-'
(\u002D'
) to indicate a negative value. The resulting long
value is returned, exactly as if the argument and the radix 10
were given as arguments to the parseLong(java.lang.String, int)
method.
Note that neither the character L
('\u004C'
) nor l
('\u006C'
) is permitted to appear at the end of the string as a type indicator, as would be permitted in Java programming language source code.