null
을 +
연산자로 연결하면 항상 "null"문자열로 변환됩니다. 이것은 첫 번째 출력 Hellonull을 설명합니다.
CONCAT 함수는 다음과 같이 내부적 같습니다
public String concat(String s) {
int i = s.length();
if (i == 0) {
return this;
} else {
char ac[] = new char[count + i];
getChars(0, count, ac, 0);
s.getChars(0, i, ac, count);
return new String(0, count + i, ac);
}
}
출처 : 당신이 볼 수 있듯이 String concatenation: concat() vs "+" operator
,이 호출 s.length가(), 귀하의 경우 어떤이 null.length을 의미한다(); 어떤 String abc= "Hello".concat(null);
문에 대한 NullPointerException이 발생합니다.
편집 : 난 그냥 내 자신의 String.concat (문자열들) 기능을 디 컴파일하고 실행 조금 다른 보이지만, NullPointerException이 이유는 동일하게 유지.