Re: Argument scope
On 02-12-2010 01:42, Stefan Ram wrote:
Here is an idea for a new scope in Java (could be
used in other languages as well):
void fill
( final int color
{ final int RED = 1;
final int GREEN = 2;
final int BLUE = 3; })
{ /* ... */ }
Now one can call this as, for example:
fill( GREEN );
But one does not need to write
fill( Class.GREEN );
or so anymore.
The scope of the identifier ?GREEN? is only the
argument expression corresponding to the parameter
?color?. So GREEN is not recognized here:
final int i = GREEN; fill( i ); /* not supported */
If ?Beta? is an interface, one can also write:
void fill( final int color import Beta ){ /* ... */ }
, to ?import? the constants of the interface Beta for
this purpose.
Or, we could have an import for Enum types:
void test( final enum Day import ){ /* ... */ }
, so that one then can write
test( MONDAY )
instead of
test( Day.MONDAY )
There are actually two questions:
1) is this a feature that is useful?
2) is this feature so useful that it is worth adding
to the complexity of the language?
I would tend to say YES and NO.
Arne