Submission: switch (...) instanceof feature
Neal Gafter
neal at gafter.com
Mon May 4 14:30:46 PDT 2009
2009/5/4 Jeroen van Maanen <jeroen at lexau.org>
> Neal Gafter schreef:
>
>> If we want a variable inside the switch statement with a different type
>> than outside, then the programmer should introduce a new variable. That
>> allows the new form of the switch statement to be used with general
>> expressions instead of only a simply-named variable. Something like this:
>>
>
> I disagree. The proposal was meant to deal with the case where a method
> gets an object of an unknown (or not completely known) type and where part
> of the method needs to perform specific actions based on the specific type.
> Currently, this situation needs a cast and a new name. I would like to do
> away with both of them, if possible. So I would like to see a scope where
> the same name is used for the same object but with a narrower type. Is can
> see the problems with getting the "switch" statement to accommodate this, so
> I'm happy very happy with the suggestion that an extension of the "if"
> statement would be more straight forward.
Any proposal that changes the type of an existing variable in a particular
scope is less straightforward, as is any proposal that works with an
expression that is a variable but not any other kind of expression, or that
treats parameters differently from other variables. Language constructs
that are not designed to be orthogonal are likely not well designed.
More information about the coin-dev
mailing list