Java – default value of local variable?

See the English answer > default values of instance variables and local variables

Who can explain?

Solution

Local variables are not initialized to default values, such as class variables The same applies to primitive and object references

Javadoc (section 4.12.5. Initial values of variables):

A local variable must be explicitly given a value before it is used,by either initialization or assignment,in a way that can be verified using the rules for definite assignment.
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>