2018-10-28 String.valueOf(null) 会报空指针异常
Albert陈凯
发布
于
2018-12-04 15:08:17
发布
于
2018-12-04 15:08:17
Why 源代码里面明明检查了null
/**
* Returns the string representation of the {@code Object} argument.
* @param obj an {@code Object}.
* @return if the argument is {@code null}, then a string equal to
* {@code "null"}; otherwise, the value of
* {@code obj.toString()} is returned.
* @see java.lang.Object#toString()
public static String valueOf(Object obj) {
return (obj == null) ? "null" : obj.toString();
* Returns the string representation of the {@code char} array
* argument. The contents of the character array are copied; subsequent
* modification of the character array does not affect the returned
* string.
* @param data the character array.
* @return a {@code String} that contains the characters of the
* character array.
public static String valueOf(char data[]) {
return new String(data);