Blocks for scope control
- From: Arved Sandstrom <asandstrom3minus1@xxxxxxxxxxx>
- Date: Sun, 15 Jan 2012 11:50:32 -0400
See
http://stackoverflow.com/questions/1563030/anonymous-code-blocks-in-java
for a general discussion.
I'm talking specifically about the block by itself: a pair of braces by
themselves, enclosing some code in a method. On occasion I do run across
situations where a judicious use of such a block inside a method, to
restrict variable visibility, is handy.
I almost never see anyone else using these things this way. A block in a
method always seems to be associated with a control construct or
exception handling. As any number of references point out, you wouldn't
expect to see many usages of local blocks, mainly because 99 times out
of 100 that situation is probably handled best by a new method. But in
my years of looking at Java it occurs to me that I barely see any use of
this at all...even where it wouldn't be a bad idea.
Any thoughts?
AHS
--
....wherever the people are well informed they can be trusted with their
own government...
-- Thomas Jefferson, 1789
.
- Follow-Ups:
- Re: Blocks for scope control
- From: Arne Vajhøj
- Re: Blocks for scope control
- From: Roedy Green
- Re: Blocks for scope control
- From: Lew
- Re: Blocks for scope control
- From: Robert Klemme
- Re: Blocks for scope control
- Prev by Date: Re: How can I use Operand (+ , - ) with Time
- Next by Date: Re: How can I use Operand (+ , - ) with Time
- Previous by thread: How can I use Operand (+ , - ) with Time
- Next by thread: Re: Blocks for scope control
- Index(es):
Relevant Pages
|