wood burning stoves 2.0*
The moose likes Java in General and the fly likes static final variable in non-static Inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "static final variable in non-static Inner class" Watch "static final variable in non-static Inner class" New topic
Author

static final variable in non-static Inner class

Prakash Rai
Ranch Hand

Joined: Jan 10, 2011
Posts: 102



As we say that static declaration is not Allowed in Non-static Inner class . Then why static final variable is allowed?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Because the compiler can get rid of the variable and just replace all uses of it with the constant.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: static final variable in non-static Inner class
 
Similar Threads
Inner Class
final local variable question
Double-standard for inner class if it is non-static vs if it is static
static modifier doubt
Static variables in inner class not allowed why?