PROPOSAL: Improved Support for Optional Object Behaviors at Runtime

Alan Snyder javalists at
Thu Mar 26 12:20:41 PDT 2009

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 wrote:


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