PROPOSAL: Improved Support for Optional Object Behaviors at Runtime

Gabriel Belingueres belingueres at gmail.com
Thu Mar 26 12:38:00 PDT 2009


I don't get it. You still need an "if" after you call the getExtension
method (thus the client code is not more object-oriented than using
instanceof).

And instanceof works on null references too.

2009/3/26, Alan Snyder <javalists at cbfiddle.com>:
> Sorry if I was not clear enough. The difference is that getExtension is a
> method, therefore it can be overridden in a subclass.
>
> On Mar 26, 2009, at 12:12 PM, rssh at gradsoft.com.ua wrote:
>
> EXAMPLE:
>
> Suppose a program wants to test an object "o" at runtime for an optional
> behavior defined by a class or interface "T". In current Java, the program
> could write:
>
>        try {
>                T t = (T) o;
>                ... use t ...
>        } catch (ClassCastException ex) {
>        }
>
> Using the proposed feature, the program would write:
>
>        T t = o.getExtension(T.class);
>        if (t != null) {
>                ... use t ...
>        }
>
> The following examples are all hypothetical, but plausible to varying
> degrees. Note that many of them use instances of existing platform
>
>
> Sorry, I can't understand, how this differ from
>
> if (o instanceof T) {
>  T t = (T)o;
>   .... use t ...
> }
>
> ?
>
>
>
>



More information about the coin-dev mailing list