[56] in java-interest
re: Proposed Java Language Extentions
daemon@ATHENA.MIT.EDU (Brian.G.Beuning@att.com)
Fri May 5 17:19:25 1995
From: Brian.G.Beuning@att.com
Date: Fri, 5 May 95 14:53:13 CDT
To: java-interest@java.Eng.Sun.COM
>(7) Instanceof and type Coercion. Postponed. It turns out that
> you often write code like:
>
> if (x instanceof Foo) {
> Foo foox = (Foo)x;
> ...
> }
>
> It would be nice if there was some construct where you could
> test if x is an instance of Foo and then use it as a Foo
> without having to cast it. We could not agree on a good syntax
> that would have little impact on the language and the runtime.
It seems Modula-3 had something like this, I think it went like this
with x in
class Foo:
/* use fields of a Foo(x) freely */
class Bar:
/* ditto for Bar(x) */
end
I never liked this statement for the same reasons C++ says
the switch statement is bad. Code like the above should
be replaced by
x.method();
where Foo.method() and Bar.method() contain the code fragments
from the branches in the 'with' statement.
Brian Beuning
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com