This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes automatic variables availability? 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 » Beginning Java
Bookmark "automatic variables availability?" Watch "automatic variables availability?" New topic
Author

automatic variables availability?

Jasper Vader
Ranch Hand

Joined: Jan 10, 2003
Posts: 284
are automatic variables never available to an inner class that has been defined in a method of the enclosing class?


giddee up
Jasper Vader
Ranch Hand

Joined: Jan 10, 2003
Posts: 284
example...
public class TestClass
{
static int si = 10; int ii = 20;
public void inner()
{
int ai = 30; //automatic variable
final int fai = 40; //automatic final variable
class Inner
{
public Inner() { System.out.println(si+" "+ii+" "+fai); }
}
new Inner();
}
public static void main(String[] args){ new TestClass().inner(); }
...
automatic variable is never available... even if inner was a static method?
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Yes, only final local variables are available to a local class.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Jasper Vader
Ranch Hand

Joined: Jan 10, 2003
Posts: 284
so an inner class can gain access to final method-local variables, and can gain access to the enclosing static and non-static class-member variables..
hmmm, i start to get confused by all these rules - still, i guess it becomes logical after a while, when you start understanding how everything locks together because of relationships, and the way things work.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: automatic variables availability?
 
Similar Threads
"Leap" and class sizes
Variables
answer this
can you figure this out?
Automatic variables