Re: inner class and static
- From: "Mike Schilling" <mscottschilling@xxxxxxxxxxx>
- Date: Tue, 18 Jul 2006 00:36:41 GMT
"jim" <jseers@xxxxxxxxx> wrote in message
news:1153180095.054378.243480@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
<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>
Is that really what it says? That's awful. What it means to say is that
local and anonymous classes can access local variables and formal parameters
that are visible in their enclosing block. For this to work, these variables
must be declared final. (Paraphrased from JLS 3, sec 8.1.3)
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?
It's a field in the enclosing class, not a local variable, so final isn't
necessary.
.
- References:
- inner class and static
- From: jim
- Re: inner class and static
- From: Matt Humphrey
- Re: inner class and static
- From: Mike Schilling
- Re: inner class and static
- From: jim
- inner class and static
- Prev by Date: Re: How Do You Tell How Long it Takes for a Piece of Code to Execute?
- Next by Date: Re: How Do You Tell How Long it Takes for a Piece of Code to Execute?
- Previous by thread: Re: inner class and static
- Next by thread: displaying text in jtextarea
- Index(es):
Relevant Pages
|