Obtaining Information About Methods
MATLAB offers several functions to help obtain information related to the Java methods you are working with. You can request a list of all of the methods that are implemented by any class. The list may be accompanied by other method information such as argument types and exceptions. You can also request a listing of every Java class that you loaded into MATLAB that implements a specified method.
Methodsview: Displaying a Listing of Java Methods
If you want to know what methods are implemented by a particular Java (or MATLAB) class, use the
methodsview function in MATLAB. Specify the class name (along with its package name, for Java classes) in the command line. If you have imported the package that defines this class, then the class name alone will suffice.
The following command lists information on all methods in the
A new window appears, listing one row of information for each method in the class. This is what the
methodsview display looks like. The fieldnames shown at the top of the window are described following the figure.
Each row in the window displays up to six fields of information describing the method. The table below lists the fields displayed in the
methodsview window along with a description and examples of each field type.
||Method type qualifiers
||Data type returned by the method
||Arguments passed to method
||Other relevant information
||Parent of the specified class
Using the Methods Function on Java Classes
In addition to
methodsview, the MATLAB
methods function, that returns information on methods of MATLAB classes, will also work on Java classes. You can use any of the following forms of this command.
methods without the
'-full' qualifier to return the names of all the methods (including inherited methods) of the class. Names of overloaded methods are listed only once.
methods returns a listing of the method names (including inherited methods) along with attributes, argument lists, and inheritance information on each. Each overloaded method is listed separately.
For example, display a full description of all methods of the
methods java.awt.Dimension -full Methods for class java.awt.Dimension: Dimension() Dimension(java.awt.Dimension) Dimension(int,int) java.lang.Class getClass() % Inherited from java.lang.Object int hashCode() % Inherited from java.lang.Object boolean equals(java.lang.Object) java.lang.String toString() void notify() % Inherited from java.lang.Object void notifyAll() % Inherited from java.lang.Object void wait(long) throws java.lang.InterruptedException % Inherited from java.lang.Object void wait(long,int) throws java.lang.InterruptedException % Inherited from java.lang.Object void wait() throws java.lang.InterruptedException % Inherited from java.lang.Object java.awt.Dimension getSize() void setSize(java.awt.Dimension) void setSize(int,int)
Determining What Classes Define a Method
You can use the
which function to display the fully qualified name (package and class name) of a method implemented by a loaded Java class. With the
-all qualifier, the
which function finds all classes with a method of the name specified.
Suppose, for example, that you want to find the package and class name for the
concat method, with the
String class currently loaded. Use the command
java.lang.String class has not been loaded, the same
which command would give the output
If you use
which -all for the method
equals, with the
java.awt.Frame classes loaded, you see the following display.
which function operates differently on Java classes than it does on MATLAB classes. MATLAB classes are always displayed by
which, whether or not they are loaded. This is not true for Java classes. You can find out which Java classes are currently loaded by using the command
[m,x,j]=inmem, described in Determining Which Classes Are Loaded.
For a description of how Java classes are loaded, see Making Java Classes Available to MATLAB.
|Invoking Static Methods on Java Classes||Java Methods That Affect MATLAB Commands|