PROPOSAL: Improved Support for Optional Object Behaviors at Runtime

rssh at gradsoft.com.ua rssh at gradsoft.com.ua
Thu Mar 26 12:12:15 PDT 2009


> 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