Home > Back-end >  Consult a String [] item=null; Calculated the initialize array? thank you
Consult a String [] item=null; Calculated the initialize array? thank you

Time:05-18

Consult a String [] item=null; Calculated the initialize array? thank you

CodePudding user response:

Not to, so that the array can not use, because you have no initial size

CodePudding user response:

This variable is initialized, can be compiled, but did not allocate memory, will directly using the null pointer

CodePudding user response:

refer to the second floor of green _ reply:
this variable initialization, can be compiled, but did not allocate memory, will directly using the null pointer

Thank you for the great god, String [] STR; And the String STR=null; Is there a difference?
thank you

CodePudding user response:

reference oracleperl reply: 3/f
Quote: refer to the second floor of green _ a reply:
this variable initialization, can be compiled, but did not allocate memory, will directly using the null pointer

Thank you for the great god, String [] STR; And the String STR=null; Is there a difference?
Thank you

I think the String STR=null; This is to see the compiler, the compiler knows it is deliberately have a null, so in the subsequent operations will no longer ask, for example, STR. The length will not complain,
But the String STR; In STR. The length, the compiler will detect and report errors, suggests that the STR uninitialized,
  • Related