• Post Reply Bookmark Topic Watch Topic
  • New Topic

final loacl variables  RSS feed

 
Ramm Kummar
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

final String z = "local variable"; // does this variable stores in heap? If so how come since its an loacl variable.

 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The variable z itself is still stored on the stack. The inner class MyInner will get a hidden field of the same type as z, and the contents of z are copied to that field (for objects, it means that the reference is copied).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!