User`s manual

Invoking Methods on Java Objects
5-27
Changing the Effect of isequal
The MATLAB isequal function compares two or more arrays for equality in
type, size, and contents. This function can also be used to test Java objects for
equality.
When you compare two Java objects using
isequal, MATLAB performs the
comparison using the Java method,
equals. MATLAB first determines the
class of the objects specified in the command, and then uses the
equals method
implemented by that class. If it is not implemented in this class, then an
inherited
equals method is used. This will be the equals method defined by the
java.lang.Object class if no intermediate ancestor classes define this method.
You can override inherited
equals methods in classes that you create by
implementing such a method within your class definition. In this way, you can
change the way MATLAB performs comparison of the members of this class.
Changing the Effect of double and char
You can also define your own Java methods toDouble and toChar to change the
output of the MATLAB
double and char functions. For more information, see
the sections entitled “Converting to the MATLAB double Data Type” and
“Converting to the MATLAB char Data Type” on page 5-58.
How MATLAB Handles Undefined Methods
If your MATLAB command invokes a nonexistent method on a Java object,
MATLAB looks for a built-in function with the same name. If MATLAB finds a
built-in function of that name, it attempts to invoke it. If MATLAB does not
find a function with that name, it displays a message stating that it cannot find
a method by that name for the class.
For example, MATLAB has a built-in method named
size, and the Java API
java.awt.Frame class also has a size method. If you call size on a Frame
object, the
size method defined by java.awt.Frame is executed. However, if
you call
size on an object of java.lang.String, MATLAB does not find a size
method for this class. It executes the MATLAB
size built-in instead.
string = java.lang.String('hello');
size(string)
ans =
1 1