Final variables are also static

Folks,
I came a cross statement saying Final variables are also static!
Is that true? if its true why they are?
Thanks
Jl

If you're initializing the final variable to the same
value for each instance, then I can see no benefit to
making it an instance variable. What does the initial value have to do with it?
By making it static,
you can 1) save memory 2) make the variable visible
outside the context of an instance which could be
useful and 3) make it more clear that the value of the
variable is not related to any particular instance
(because it isn't even though it could be declared as
an instance variable). If the variable is supposed to be static under the design then yes, you get all the things you just mentioned. But whether each instance has the same initial value is pretty much irrevlevant to that.
Point 2 is arguable because
maybe you specifically want to require an instance
before accessing the variable. Also, if you're
initializing the variable to different values for
different instances then of course that's a different
story.Suppose I want to count the number of times methodX has been called on each instance of a class. If I use an instance variable to count the calls, then the initial value would be zero for each instance. It would make little sense to try and use a static variable.

Similar Messages

  • Final variable implicitely static?

    Hello,
    I have a question about java language fundamentals.
    Suppose I have a variable myVar declared in the body of a class as final as follows:
    public class MyClass {
    final int myVar;
    }I infer from this that myVar is implicitely static. Am I right?
    Thanks in advance,
    Balteo.

    Thanks,
    Mattbunch's test demonstrates that interface variables are implicitely static. (MyInterface.VAR) See code below.
    public interface MyInterface {
    int VAR = 5;
    public class Test {
         public static void main(String[] args){
            //Demonstrates that interface variables are implicitely static
            System.out.println(MyInterface.VAR);
    }Thank you all for your contributions,
    Balteo.

  • Overloading a static final variable

    This is a question from a book. I am not sure of overloading a constructor with a static final variable. Here is the class
    public class Pizza{
    private static final double cost_price = 10.0;
    String topping;
    double price;
    }next, the question wanted me to create a constructor to override the topping and the price of the original constructor so i did
    public Pizza(String t, double p){
    topping = t;
    price = p;
    }Next it wants me to override the constructor another time only by receiving one parameter which is the topping by calling the above constructor but instantiate the price to the constant price which is the final static variable.
    public Pizza(String t){
    cost_price = p;
    this(t, p);
    }I dont know if the above solution that i did is correct as it maybe have some correction to be made because of the static final variable or the above code does not work. Please help me to verify thank you

    Sorry but what does it means? Do you have any
    solution? I would appreciate it .The last one should look like this:
    public Pizza(String t){
       this(t, cost_price);
    }

  • Final variables

    Hello All
    I have a question and this contradicts what I have learned so I will like to have a good explanation for this.
    public class Foo {
    private final int x = 5;
    private byte b = x;
    will this compile? The answer is YES it will compile. Now if you take out the final keyword from int x will it compile? The answer is NO it will not.
    Why is this???????
    Thanks in Advance for your help!!!!

    sorry, but my compiler (jdk1.3) compiles the code :
    public class test
    private int x = 5;
    private int b = x;
    There is one thing you are missing is that it is instead of int b it should be byte b, now let see if you can make the above code compile under the jdk1.3 compiler. Now change the private int x to private final int x and compile your code...
    I think the compiler inserts an implicit (invisible)
    constructor that is called before any other explicitly
    defined constructor. And this implicit constructor
    makes the assignments, and thus you can use any
    non-static and non-final expression for
    initialization. Even this :
    class a
    int x;
    class b
    int y = x;
    And this really makes sense !!!
    When class a instanciates class b (if there was an
    explicit constructor), the implicit constructor first
    assigns x to y and after that the explicit constructor
    is called.
    also think of that :
    public class test
    int x;
    int y = x;
    this also compiles, because all variables are always
    (implicitly) initialized with 0 (and corresponds like
    false and null).
    enough ?I think you are right the compiler might insert an implicit(invisible) constructor, but the above explanation still doesn't explain why it treats final variable differently then non-final variables??? Thanks for replying!!!!

  • HELP: Cannot refer to non-final variable inside inner class

    Below is a function that WAS working beautifully. I had to restructure many things in my code base to suit a major change and I have to make this function static. Since I made this function static, I get some errors which are displayed in comments next to the line of code.
    Can anyone offer any advice how to fix this?
    static private void patchSource( final Target target, final TargetResolver resolver, final TexSheetCommand args ) throws Exception
         boolean bDone = false;
         Element e;
         SAXReader sax          = new SAXReader();
         FileInputStream fis     = new FileInputStream( args.getInputFile() );
         Document document     = sax.read( fis );
         Element root = document.getRootElement();
         if( root.getName().equals( "Sheet" ) )
              XMLParser.iterateElements( root,     new XMLElementCallback()
                                                      public void onElement( Element element )
                                                           XMLParser.iterateAttributes( element,     new XMLAttributeCallback()
                                                                                                   public void onAttribute( Element element, Attribute attribute )
                                                                                                        if( attribute.getName().equals( "guid" ) )
                                                                                                             e = element; // PROBLEM: Cannot refer to a non-final variable e inside an inner class defined in a different method
                                                                                                             // WARNING: Type safety: The expression of type Iterator needs unchecked conversion to conform to Iterator<Attribute>
                                                                                                             for( Iterator<Attribute> it = element.attributeIterator(); it.hasNext(); )
                                                                                                                  Attribute a = (Attribute)it.next();
                                                                                                                  if( a.getName().equals( "randOffset" ) )
                                                                                                                       Integer i = new Integer( resolver.getTotalPermutations() );
                                                                                                                       a.setValue( i.toString() );
                                                                                                                       bDone = true; // PROBLEM: Cannot refer to a non-final variable bDone inside an inner class defined in a different method
              if( ( !bDone ) && ( e != null ) )
                   Integer i = new Integer( resolver.getTotalPermutations() );
                   e.addAttribute( "randOffset", i.toString() );                                                                                                                                            
         FileOutputStream fileOut     = new FileOutputStream( args.getInputFile() );          
         OutputFormat format               = OutputFormat.createPrettyPrint();          
            XMLWriter xmlWriter               = new XMLWriter( fileOut, format );
            xmlWriter.write( document );
            fileOut.close();
    }PS.) on a side note there is a warning on one of the lines too. Can anyone offer help on that one too?!
    Thanks in advance.

    It is already set to that - it does look correct in Eclipse, honest.
    It's just the block that's gone crazy with the formatting. I've spent around 10 minutes trying to tweak it just so it displays correctly but it wasn't making sense.
    I'd rather not turn this conversation into a judgement of my code-style - I already understand that it doesn't conform to the 'Java way' and I've had Java programmers bash me about it for a long time.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to reference a static variable before the static initializer runs

    I'm anything but new to Java. Nevertheless, one discovers something new ever' once n a while. (At least I think so; correct me if I'm wrong in this.)
    I've long thought it impossible to reference a static variable on a class without the class' static initializer running first. But I seem to have discovered a way:
    public class Foo  {
      public static final SumClass fooVar;  // by default initialized to null
      static  {
         fooVar = new SumClass();
    public class Bar  {
      public static final SumClass barVar;
      static  {
         barVar = Foo.fooVar;  // <<<--- set to null !
    }Warning: Speculation ahead.
    Normally the initial reference to Foo would cause Foo's class object to instantiate, initializing Foo's static variables, then running static{}. But apparently a static initializer cannot be triggered from within another static initializer. Can anyone confirm?
    How to fix/avoid: Obviously, one could avoid use of the static initializer. The illustration doesn't call for it.
    public class Foo  {
      public static final SumClass fooVar = new SumClass();  // either this ..
    public class Bar  {
      public static final SumClass barVar = Foo.fooVar;  // .. or this would prevent the problem
    }But there are times when you need to use it.
    So what's an elegant way to avoid the problem?

    DMF. wrote:
    jschell wrote:
    But there are times when you need to use it. I seriously doubt that.
    I would suppose that if one did "need" to use it it would only be once in ones entire professional career.Try an initializer that requires several statements. Josh Bloch illustrates one in an early chapter of Effective Java, IIRC.
    Another classic usage is for Singletons. You can make one look like a Monostate and avoid the annoying instance() invocation. Sure, it's not the only way, but it's a good one.
    What? You only encounter those once in a career? We must have very different careers. ;)
    So what's an elegant way to avoid the problem? Redesign. Not because it is elegant but rather to correct the error in the design.<pff> You have no idea what my design looks like; I just drew you a couple of stick figures.If it's dependent on such things as when a static initializer runs, it's poor. That's avoidable. Mentioning a case where such a dependency is used, that's irrelevant. It can be avoided. I know this is the point where you come up with a series of unfortunate coincidences that somehow dictate that you must use such a thing, but the very fact that you're pondering the problem with the design is a design problem. By definition.
    Besides, since what I was supposing to be a problem wasn't a problem, your "solution" isn't a solution. Is it?Well, you did ask the exact question "So what's an elegant way to avoid the problem?". If you didn't want it answered, you should have said so. I'm wondering if there could be any answer to that question that wouldn't cause you to respond in such a snippy manner. Your design is supposedly problematic, as evidenced by your question. I fail to see why the answer "re-design" is unacceptable. Maybe "change the way the Java runtime initializes classes" would have been better?
    This thread is bizarre. Why ask a question to which the only sane answer, you have already ruled out?

  • Final Variable changed on runtime...

    Hello, I recently did a test with my program, which involved the use of 32 clients connecting to a server from a single application, however on runtime, the some final variables had their values changed, for example
    private static final Point point1 = new Point(100,100);
    had changed values to 480,360, and the default Point in my Point class had changed it's value from 0,0 to another value as well. How is this possible? The only methods used on the finalized point was equals/distance, which both do not affect the private fields of point, yet they were changed after logging in about 29 clients or so.
        public int distance(Point p2)
            return Math.max(Math.abs(p2.x - x), Math.abs(p2.y - y));
        public boolean equals(Point p)
            return (p.x == x && p.y == y);
        public boolean equals(Object obj)
            if (obj instanceof Point)
                return (((Point) obj).x == x && ((Point) obj).y == y);
            return false;
        }And here is where they are used
        private static final Point mine = new Point(167, 105);...
                        if (!cLoc.equals(mine))
                            if (cLoc.distance(mine) <= 18)
                                Player.jump(mine);
                                Player.Mine();
                                lastMineTime = 0;
                        }Any idea why this happened?

    Sorry, I was not clear enough
    Here is my Point class
    http://pastebin.com/m6075a9d8
    Now, after logging on about 38 clients (about 204 threads lol....), the constant fields get changed, for example within the point class, the "DEFAULT" gets changed to a random variable (which never happened before when logging on 10-20 only)
    Same goes for my other constant variables, their values get changed.
    For Example these Points:
        private static final Point sellPoint = new Point(417, 357);
        private static final Point mineExit = new Point(156, 90);
        private static final Point mineExitPoint = new Point(53, 399);
        private static final Point mineEntrance = new Point(45, 397);
        private static final Point mine = new Point(167, 105);Would get changed to something totally different, while the only functions used on those points are equals/distance.
    Here is an image of the Point instance while in debug mode:
    http://img193.imageshack.us/img193/6774/javaerror.jpg
    As you can see , mineExit takes the place of mineExitPoint (however I don't know why..), and mineExitPoint remains the same.....
    Another image:
    http://img6.imageshack.us/img6/9088/javaerror2.jpg
    Edit: Could it be the fact that around 30 threads are checking the same static/final variable at once?
    Edited by: Naki on Jul 1, 2009 6:43 PM

  • Interface member variable by defaultly static ?

    Hi,
    The interface member variable by defaulty public,static,final.
    But i have one doubt.
    It is public because it has to access out side the interface.
    It is final because the value never changes
    Why it should be static ???
    Thanks,
    Narendra babu.B

    Member variables are an implementation detail. Java does not allow multiple implementation inheritance. Java does allow multiple subtyping through interfaces. So interfaces can't have member variables.
    Consider the diamond of death:
    interface A
        int x;
    interface B extends A
    interface C extends A
    interface D extends B, C
    }See the problem now?

  • Interfaces and final variables

    So I understand that I am not supposed to put my final variables or constants into an interface, but then where?
    I have 2 classes that implement an interface, and they both allow listerners to be added to them, through that interface. They both fire property events on the listener with the same property. Currently I just put the property id constants into one class and reference it from the other. But it appears to me the best place for the definition of these common properties is in the interface!?

    So If you read over all the postings, you'll know exactly why they say, never to create classes for the purpose of grouping constants, it is confusing.
    More explicitly, it is lazy. The reason you are grouping the constants has nothing to do with the relationship between the constants and their use within the program, you are grouping them because you are tired of typing a long declaration everytime you want to use them within the program. So, the overall design of your program is being warped by design decisions that are based on laziness.
    The reason people put them in interfaces, "public interface Globals...", is so that importing that namespace through inheritance doesn't suck up that "valuable" superclass (which I will have to remember to rant about on some other thread). It is probably the case that the most efficient way to do this is to use static getters: getPI(), getOrigin(), getNewYears(), whatever. You will see an awful lot of constants that have been replaced over the years with getters. As the code matures, it isn't peculiar to see the flexibility of the programme being reduced or impeded by the constraints and constants implicit in the codesbase.
    Andrew

  • Whats the meaning when variables are enclosed by brackets

    Hi,
    Whats the meaning when variables are enclosed by brackets?
    like say
    lv_fieldname(25) TYPE c.
    lv_fieldname  = 'Material01'.
    what does it mean by saying
    ASSIGN (lv_fieldname) TO <fs_fieldname>.

    In many statement in ABAP, brackets mean that real "name" of operand (object) will be determined during runtime.
    Normally you would write
    data lv_fieldname(25) TYPE c VAUE 'SOME_FIELD'.
    assign lv_fieldname to <fs>.
    write: <fs>.
    This code is static . It means that when syntax check takes place, compilator looks for definition of lv_fieldname.
    It then assigns value of this field. The resuts is printintg on screen text "SOME_VALUE"
    Now you have similar code, but with brackets
    data: lv_fieldname(25) TYPE c VAUE 'SOME_FIELD',
             some_field type i vlaue 5.
    assign (lv_fieldname) to <fs>.
    write: <fs>.
    Here code is dynamic . It means that compilator doens't realy know the field name which will be assigned to <fs>.
    We told him that this will be determined during runtime ( by means of brackets ) and the real field name we want to assing, is stored in LV_FIELDNAME.
    This is equal to writing
    assign ('SOME_FIELD') to <fs>.
    When program starts, it is no LV_FIELDNAME which is assinged to <fs>, but the field which is stored in LV_FIELDNAME, namely 'SOME_FIELD'.
    So the printed result will be 5 .
    The same rule with dynamic operands applies i.e. in select statement
    data: my_table(5) type c value 'SPFLI'.
    select * from (my_table) ...
    There is no table in DB named my_table , but compilator "knows" that we don't what to fetch data from MY_TABLE, but we want table name to be determined dynamically (during runtime). So, it is  'SPFLI' table which here will be taken into account.
    One more note!
    Such dynamic statements are generic (doesn't constitute fixed code) and open new range of possiblities.
    Simple extending above example will create flexible (generic) program which can fetch data from different tables with one statement.
    parameters: pa_tabname(40) type c.
    select * from (pa_tabname) into ....
    Of course here you need also dynamic internal table as target area, but this is of no importance here.
    Hope this claryfies magic with brackets;)
    Regards
    Marcin

  • "final" variable problem

    hi plz consider the code below
    (sorry if it is not in the format required i clicked on the code button on top but could not get anything)
    class A {
    public final String a = "A";
    public String b = "B";
    class B {
    public static void main(String args[]) {
      A obj = new A();
      System.out.println(obj.a);
      System.out.println(obj.b);
    }Compile the classes and the output is
    A
    B
    Now I Exchange the values of class A, so variable a gets "B" and b gets "A" and compile class A ONLY.
    Now the ouput is
    A
    A
    Can anyone please explain this
    Thanks

    Referencing final variables that contain primitive
    types or String that are initialized with a constant
    is handled as if the exact same constant was placed
    into the referencing file. Why that decision was
    made, I don't know.
    Efficiency:
    public final primitives are usually used as constants, often in place of enumeration values (pre Tiger). in-lining them means that the class in which they're defined doesn't even have to be loaded at run-time.
    Furthermore there are cases where knowing the value at compile time is essential, e.g. in case labels, and where it helps a lot (e.g. in boolean expressions).
    And the moral is; try to use them only as constants. If you have less constant constants (e.g. URLs, filepaths etc.) stick them in a properties file or something.

  • Defining a FINAL Variable?

    1. What is the advantage of defining a variable as final.?
    For example:
    In the System class,which is a final class,the static
    field variable 'out' is final.
    public final class System{
    public static final PrintStream out;
    2.Do we ever need to define a final variable ?
    3.Can a class which is not final have a final variable?

    This should not happenI've been tripped up by precisely this happeningon
    occasion.I haven't, at least not as far as public finalstatic
    variables are concerned.andyba,
    I'm about to bet my right hand on the fact that you
    are wrong. Just look at the compiled classfiles (in a
    disassembler, or decompiler). The original class that
    held the constant isn't referenced.
    You can read more on this in this article:
    http://www.javaworld.com/javaworld/javaqa/2003-03/02-qa
    0328-constant.html
    "According to the Java Language Specification, any
    static final field initialized with an expression that
    can be evaluated at compile time must be compiled to
    byte code that "inlines" the field value. That is, no
    dynamic link will be present inside class Main telling
    it to obtain the value for A from InterfaceA at
    runtime. "
    /KajOk, I admit that the JLS enforces inlining of references to final static fields that are initialised by an expression that is evaluable at compile time means I was wrong on that count.
    One reason why I am rarely, if ever, caught out by this is because I don't make regressive API changes, in this instance that means static final initialized field values do not change once they are fixed.
    Note I did say that API changes of any nature do not "require" a recompilation, I said that it is recommended and therefore a sensible thing to do.
    It is practically a golden rule in Software Development that once an API becomes public no
    regressive/subtractive changes to that API should be made. This is one reason why the Java APIs are
    becoming cluttered with deprecated annotations all over the place and why, to date, you rarely see
    regressive/subtractive API changes in Java.
    This rule has to be treated as "golden" simply because you will not always have the chance to recompile your code when deploying your application.
    This can be especially problematic when deploying Remote or Web/EJB Applications to container platforms that are not known at development time.

  • Mysterious final variables

    Can someone explain me the following behavior:-
    class Test1 {
         public static void main(String a[]){
              byte b = 1;
              char c = 'a';
              c = b; //==>Compiler throws "Type mismatch: cannot convert from byte to char "
    class Test2 {
         public static void main(String a[]){
              final byte b = 1; // Declared as final
              char c = 'a';
              c = b; //==> Compiles Successfully
    We know that we can't assign a byte to a char without a explicit cast but when we use final byte variable it doesn't complain. Why?
    Thanks
    Ashwani

    Hi,
    I think+ the answer is that a final variable initialized with a literal may be replaced throughout the code on compiletime.
    Thus the code in Test2
    class Test2 {
         public static void main(String args[]) {
              final byte b = 1; // Declared as final
              char c = 'a';
              c = b; // ==> Compiles Successfully
    }the compiler can replace with:
    class Test2 {
         public static void main(String args[]) {
              char c = 'a';
              c = 1;
    }And it explains also why this will fail, where the final variable is not initialized with a literal
    class Test2 {
         public static void main(String args[]) {
              byte a = 1;
              final byte b = a; // Declared as final
              char c = 'a';
              c = b; // ==> Compiles Successfully
    }- Roy

  • Problem with final variables and inner classes

    variables accessed by inner classes need to be final. Else it gives compilation error. Such clases work finw from prompt. But when I try to run such classes through webstart it gives me error/exception for those final variables being accessed from inner class.
    Is there any solution to this?
    Exception is:
    java.lang.ClassFormatError: com/icorbroker/fx/client/screens/batchorder/BatchOrderFrame$2 (Illegal Variable name " val$l_table")
         at java.lang.ClassLoader.defineClass0(Native Method)
         at java.lang.ClassLoader.defineClass(ClassLoader.java:502)
         at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
         at com.sun.jnlp.JNLPClassLoader.defineClass(Unknown Source)
         at com.sun.jnlp.JNLPClassLoader.access$1(Unknown Source)
         at com.sun.jnlp.JNLPClassLoader$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
         at com.icorbroker.fx.client.screens.batchorder.BatchOrderFrame.<init>(BatchOrderFrame.java:217)
         at com.icorbroker.fx.client.screens.batchorder.BatchOrderViewController.createView(BatchOrderViewController.java:150)
         at com.icorbroker.fx.client.screens.RealTimeViewController.initialize(RealTimeViewController.java:23)
         at com.icorbroker.fx.client.screens.batchorder.BatchOrderViewController.<init>(BatchOrderViewController.java:62)
         at com.icorbroker.fx.client.screens.displayelements.DisplayPanel$3.mousePressed(DisplayPanel.java:267)
         at java.awt.Component.processMouseEvent(Component.java:5131)
         at java.awt.Component.processEvent(Component.java:4931)
         at java.awt.Container.processEvent(Container.java:1566)
         at java.awt.Component.dispatchEventImpl(Component.java:3639)
         at java.awt.Container.dispatchEventImpl(Container.java:1623)
         at java.awt.Component.dispatchEvent(Component.java:3480)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450)
         at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3162)
         at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
         at java.awt.Container.dispatchEventImpl(Container.java:1609)
         at java.awt.Window.dispatchEventImpl(Window.java:1590)
         at java.awt.Component.dispatchEvent(Component.java:3480)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)

    I've also been having the same problem. The only work-around seems to be to slightly change the code, recompile & hope it works. See http://forum.java.sun.com/thread.jsp?forum=38&thread=372291

  • Problem with final variables and inner classes (JDK1.1.8)

    When using JDK1.1.8, I came up with following:
    public class Outer
        protected final int i;
        protected Inner inner = null;
        public Outer(int value)
            i = value;
            inner = new Inner();
            inner.foo();
        protected class Inner
            public void foo()
                System.out.println(i);
    }causing this:
    Outer.java:6: Blank final variable 'i' may not have been initialized. It must be assigned a value in an initializer, or in every constructor.
    public Outer(int value)
    ^
    1 error
    With JDK 1.3 this works just fine, as it does with 1.1.8 if
    1) I don't use inner class, or
    2) I assign the value in initializer, or
    3) I leave the keyword final away.
    and none of these is actually an option for me, neither using a newer JDK, if only there is another way to solve this.
    Reasons why I am trying to do this:
    1) I can't use a newer JDK
    2) I want to be able to assign the variables value in constructor
    3) I want to prevent anyone (including myself ;)) from changing the value in other parts of the class (yes, the code above is just to give you the idea, not the whole code)
    4) I must be able to use inner classes
    So, does anyone have a suggestion how to solve this problem of mine? Or can someone say that this is a JDK 1.1.8 feature, and that I just have to live with it? In that case, sticking to solution 3 is probably the best alternative here, at least for me (and hope that no-one will change the variables value). Or is it crappy planning..?

    You cannot use a final field if you do not
    initialize it at the time of declaration. So yes,
    your design is invalid.Sorry if I am being a bit too stubborn or something. :) I am just honestly a bit puzzled, since... If I cannot use a final field in an aforementioned situation, why does following work? (JDK 1.3.1 on Linux)
    public class Outer {
            protected final String str;
            public Outer(String paramStr) {
                    str = paramStr;
                    Inner in = new Inner();
                    in.foo();
            public void foo() {
                    System.out.println("Outer.foo(): " + str);
            public static void main( String args[] ) {
                    String param = new String("This is test.");
                    Outer outer = new Outer(param);
                    outer.foo();
            protected class Inner {
                    public void foo() {
                            System.out.println("Inner.foo(): " + str);
    } producing the following:
    [1:39] % javac Outer.java
    [1:39] % java Outer
    Inner.foo(): This is test.
    Outer.foo(): This is test.
    Is this then an "undocumented feature", working even though it shouldn't work?
    However, I assume you could
    get by with eliminating the final field and simply
    passing the value directly to the Inner class's
    constructor. if not, you'll have to rethink larger
    aspects of your design.I guess this is the way it must be done.
    Jussi

Maybe you are looking for

  • How do I get my Apple TV Screensaver to play an album other than Photostream?

    How do I get my Apple TV Screensaver to play an album other than Photostream?

  • Strange RowSetIterator Issue

    Hi Can anyone help with this little problem I have a delete iterator in the following code, but it's deleting one less than the number of records it should do. Code is: int errorCount = this.getErrorsPOVO_Headers().getFetchedRowCount(); RowSetIterato

  • Calm down

    Lots of folks have gotten some serious bunches in their undies here over problems with the Mac App Store, but let's calm down and step back for a minute. Consider... *The Mac App Store is brand new* If something doesn't work just yet, back off, give

  • Prompting to save report.

    I support a program that generates a report in PDF format. One of my users is now being prompted to save the report every time they view it. In the past this was not the case, they could generate the report and print and close with no prompt to save.

  • Problems Launching Photoshop from Creative Cloud

    I have a subscription to Creative Cloud but today when I tried to launch Photoshop I was told my trial ended and need to pay. I've been paying for 5 months now. What's going on?