External Interfaces/API | ![]() ![]() |
Determining the Class of an Object
To find the class of a Java object, use the query form of the MATLAB function, class
. After execution of the following example, frameClass
contains the name of the package and class that Java object frame
instantiates.
frameClass = class(frame)
frameClass =
java.awt.Frame
Because this form of class
also works on MATLAB objects, it does not, in itself, tell you whether it is a Java class. To determine the type of class, use the isjava
function,which has the form
x = isjava(obj)
isjava
returns 1
if obj
is Java, and 0
if it is not.
isjava(frame) ans = 1
To find out whether or not an object is an instance of a specified class, use the isa
function, which has the form
x = isa(obj, 'class_name
')
isa
returns 1
if obj
is an instance of the class named 'class_name
', and 0
if it is not. Note that 'class_name
' can be a MATLAB built-in or user-defined class, as well as a Java class.
isa(frame, 'java.awt.Frame') ans = 1
![]() | Accessing Private and Public Data | Invoking Methods on Java Objects | ![]() |