Article View: borland.public.jbuilder.java.language
Article #8090Re: Local Variable Needs to be Declared Final
From: Dave Bird
Date: Tue, 24 Apr 2001 20:39
Date: Tue, 24 Apr 2001 20:39
36 lines
2624 bytes
2624 bytes
In article <3ae50e3c$1_1@dnews>, Harry Whitehouse <harry@envmgr.com>
writes
>Well, I guess it's time to learn about the modifier "final"!
>
>I'm trying to spawn a thread for the printer dialog on my applet, so the
>dialog has time to close on slower connections without blanking the
>underlying applet GUI. Heaven knows if my approach is even correct (that's
>another question <g>) but for now I need to understand about the compiler
>error message indicated a local variable (in this case printerJob) needs to
>be declared final. I've seen this in some other threads I've created (to
>handle URL transactions), but have managed to sidestep this issue by
>declaring and using non-local variables.
>
>First, what is the proper syntax for this? I've tried some obvious
>permutations but with no luck.
>
>And second, what is the significance of this modifier?
Final has two different meanings. A final VARIABLE is a "constant"
in the precise sense that it is given a value when the class is
created and cannot have its contents changed (it need not be
literally a fixed value known at compile time). A final METHOD
cannot be over-ridden in subclasses.
I do not know why, but clearly some values are expected to be fixed
and unchanging: presumably if you change the print-job in use
on the fly things go haywire.
You just write it same as public or whatever before the type:
final MyClass theObject = new MyClass(); // once assigned this
// can't be modified
--
^-^-^-@@-^-;-^ http://www.xemu.demon.co.uk/
(..)__u news:alt.smoking.mooses
Technical Details
Message-ID:
<mpxL$VBASe56Ew$0@xemu.demon.co.uk>Path:
arc1-ca.pugleaf.net!newsfeed.google.com!sn-xit-03!supernews.com!newsfeed.wirehub.nl!news.maxwell.syr.edu!newsfeed.icl.net!dispose.news.demon.net!news.demon.co.uk!demon!xemu.demon.co.uk!daveReferences:
<3ae50e3c$1_1@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,4be1a32d6ef1248 X-Google-Attributes: gidf74b3,public X-Google-ArrivalTime: 2001-04-24 13:54:02 PST Path: arc1-ca.pugleaf.net!newsfeed.google.com!sn-xit-03!supernews.com!newsfeed.wirehub.nl!news.maxwell.syr.edu!newsfeed.icl.net!dispose.news.demon.net!news.demon.co.uk!demon!xemu.demon.co.uk!dave From: Dave Bird <dave@xemu.demon.co.uk> Newsgroups: borland.public.jbuilder.java.language Subject: Re: Local Variable Needs to be Declared Final Date: Tue, 24 Apr 2001 21:39:28 +0100 Organization: none Message-ID: <mpxL$VBASe56Ew$0@xemu.demon.co.uk> References: <3ae50e3c$1_1@dnews> NNTP-Posting-Host: xemu.demon.co.uk X-NNTP-Posting-Host: xemu.demon.co.uk:158.152.196.209 X-Trace: news.demon.co.uk 988145530 nnrp-07:24079 NO-IDENT xemu.demon.co.uk:158.152.196.209 X-Complaints-To: abuse@demon.net MIME-Version: 1.0 X-Newsreader: Turnpike Integrated Version 5.00 U <dQumtnY$x4rJ2u5tL5fS$n2vuP> Lines: 36