Re: inner class and static




"Matt Humphrey" <matth@xxxxxxxxxxxxxx> wrote in message
news:QcKdnauD-daeiyHZnZ2dnUVZ_s-dnZ2d@xxxxxxxxxxxxxxx

"jim" <jseers@xxxxxxxxx> wrote in message
news:1153161800.679433.165030@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I was told that the variable accessed inside a anonymous inner class
needs to be static.

An inner class (whether anonymous or not) may access the instance
variables of the outer class and it can access the local variables of the
method that instantiates it, provided they are final.


Though a *static* inner class can only access static field of its enclosing
class (and can only call static methods of that class); pehshps that's what
the OP was thinking of.


.



Relevant Pages

  • Re: Updating GUI & Running Program (AND accessing common variables!)
    ... >anonymous inner class cannot access variables from the outer class unless ... >have no problem accessing the variables in the outer class. ... Finalize is not the same as final. ... have local variables. ...
    (comp.lang.java.gui)
  • Re: Updating GUI & Running Program (AND accessing common variables!)
    ... >>You need to clarify what you mean by 'in the outer class'. ... >>An anymous inner class relies on some compiler magic. ... >>copies the values of all local variables into corresponding variables of ... an anonymous inner class can only access local ...
    (comp.lang.java.gui)
  • Re: inner class and static
    ... An inner class may access the instance variables ... of the outer class and it can access the local variables of the method that ...
    (comp.lang.java.programmer)
  • Re: Why must and must not be "final" ?
    ... It's an ugly but effective workaround when an anonymous inner class ... needs access to local variables or parameters that you want to change. ...
    (comp.lang.java.programmer)
  • Re: Serialization ?
    ... I find its actually better to use public static methods, ... I define and use the local variables in BizTalk. ... Yes, you can access static methods from your non-serializable class, ...
    (microsoft.public.biztalk.general)