[54] in java-interest

home help back first fref pref prev next nref lref last post

Instanceof and type Coercion.

daemon@ATHENA.MIT.EDU (James Cownie)
Fri May 5 14:54:02 1995

Date: Fri, 5 May 1995 14:23:32 +0000
From: jim@meiko.co.uk (James Cownie)
To: java-interest@java.Eng.Sun.COM

> These are the notes on the Java Language meeting of Thursday the 4th of May.
...
> (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 like you're after something similar to the C++ "dynamic_cast"
operator (discussed at some length by Stroustroup on page 308 of
Design and Evolution of C++). Of course you don't need all the
grievous syntax associated with it there :-). He does make some
reasonable arguments for why combining the test and cast is a good
thing. 

-- Jim 

James Cownie 
Meiko Limited			Meiko Inc.
650 Aztec West			130C Baker Avenue Ext.
Bristol BS12 4SD		Concord
England				MA 01742

Phone : +44 1454 616171		+1 508 371 0088
FAX   : +44 1454 618188		+1 508 371 7516
E-Mail: jim@meiko.co.uk   or    jim@meiko.com
WWW   : http://www.meiko.com/welcome.html

-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post