Re: inner class and static
- From: "jim" <jseers@xxxxxxxxx>
- Date: 17 Jul 2006 16:48:15 -0700
<Quote from TIJ3 chapter 8>
If you're defining an anonymous inner class and want to use an object
that's defined outside the anonymous inner class, the compiler
requires that the argument reference be final, like the argument to
dest( ). If you forget, you'll get a compile-time error message.
Feedback
</Quote>
The txt mentioned in the original post is an object that's defined
outside the anonymous inner class, but still the compiler didn't
complain, why?
Mike Schilling wrote:
"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.
.
- Follow-Ups:
- Re: inner class and static
- From: Mike Schilling
- Re: inner class and static
- References:
- inner class and static
- From: jim
- Re: inner class and static
- From: Matt Humphrey
- Re: inner class and static
- From: Mike Schilling
- inner class and static
- Prev by Date: Re: Why not written in Java?
- Next by Date: Re: what's better way to store a million keys in mem?
- Previous by thread: Re: inner class and static
- Next by thread: Re: inner class and static
- Index(es):
Relevant Pages
|