Casting Objects

In some cases it is necessary to cast the internal representation of an object as well as the Java object. (For example, getting an object from a SIDL array of superclass objects.) In these cases a Java cast is insufficient. Therefore we have provided two casting functions.

_cast(object) is a static function included with every SIDL class that returns object passed in to cast that class. For example, in order to cast an object of type sidl.BaseClass to foo.Bar simply write foo.Bar newobj = (foo.Bar) foo.Bar._cast(oldobj). If this is an invalid cast, _cast will return null.

The alternative is _cast2(``ClassName''). This is a cast function that is included with every SIDL object. It performs basically the same function as _cast, but the form is object._cast2(``ClassName''). It takes a fully qualified class name. If the cast is invalid, or a class of that name cannot be found, this function returns null.

Both of these functions return a sidl.BaseClass which then must be Java casted to the correct Java class type. Also, in casting, they both create a new Java object that owns a new reference to the IOR object. In Java you never have to worry about reference counting, but this does mean that the pre-cast object still exists and is valid.



babel-0.10.2
users_guide Last Modified 2005-03-23

http://www.llnl.gov/CASC/components
components@llnl.gov