Why String concatenate null with + operator and throws NullPointerException with concate() method

后端 未结 9 1873
别那么骄傲
别那么骄傲 2021-02-04 06:23

Here is my class, where i am concatenating two string. String concatenate with null using + operator execute smoothly but throws NullPointerException

9条回答
  •  时光取名叫无心
    2021-02-04 06:28

    concate() method creates new String() object under the hood.

    where as + combines\ concatenates values by using toString() method. That's why when we use + it continents "somevalue".append(null).toString().

    for reference see this question.

提交回复
热议问题