I've looked all over, but do not see [a b] = methods(classname)
documented. I mean, the single variable output is documented, but not two-variable output. I see no documentation in MATLAB or on undocumented matlab, or even here. Maybe I missed it?
If I call it with a matlab class, char
for example
[a b] = methods(char);
Then a
is the list of methods for char, and b
is []
BUT...
For a java class, b
takes on some useful values. Assume that javaClass
is a java class or java class name.
Typically, I would either call a = method(javaClass)
or a = method(javaClass,'-full')
. However, I noticed that I can ALSO call
[a b] = method(javaClass)
When I do:
a
is a cell containing a unique list of all the classes method names. (as expected)b
is a N x 6 cell of strings with each column representing:
'static'
if static, []
otherwise()
[]
Example:
[a b] = method(java.lang.Integer);
Then, a
is a <32x1 cell> containing simple names, such as 'Integer'
, 'bitCount'
, etc.
But, b
is a <43x6 cell> containing each variation of each function. For example, one of the valueOf functions would show
COL VALUE
1. static
2. java.lang.Integer
3. valueOf
4. java.lang.Integer.valueOf
5. (java.lang.String)
6. throws java.lang.NumberFormatException`
Main question: Is this entirely unsafe to use? Because it's undocumented, I'll assume so; however it provides me with some built-in functionality that would be nice to not have to duplicate. The work-around for parsing isn't odious, but this functionality is already here.
Where does this come from? That is, Is this actually from the MATLAB function, or is there some Java function that it is using?
Does anyone use it? Or (as in Main question) should it just be avoided?
IS there documentation on this? Beyond this post I mean. I mean, sure, it appears to be a straight forward function.... And is this even interesting enough to anyone that it would matter?
I'm on MATLAB 2011b, does this functionality still exist in later versions of MATLAB ( 2013a )?
For MATLAB's own classes (classdef
style), you can use the metadata system to get similar information:
mc = ?timer
mc.MethodList
The use of methods
you've shown above seems to be particularly useful for Java classes and objects. Inspect the source code of methodsview
function which internally use the two outputs of methods
.
edit methodsview
Matlab includes numerous such undocumented nuggets, that I am documenting in my UndocumentedMatlab.com website since 2009 (the site had its 4th birthday a few days ago). Most of these relate to the Matlab-Java interface (on which I wrote a book), but there are also many pure-Matlab undocumented features and functions that can be quite useful.
Some of these features are more risky than others in terms of future Matlab-compatibility. I consider the second output arg of methods
to be of low risk. It is indeed undocumented, but has existed in its current form for ages (at least a decade, possibly more). It is still available as of R2013a. As Amro stated, it is used by the internal methodsview
function and is entirely safe to use.
If you are interested in getting information about a Java object in Matlab, consider using the uiinspect
or checkClass
utilities, that provide much more information than either methods
or methodsview
. Both uiinspect
and checkClass
work on multiple types of object handles and class-names, including Java, COM, Matlab classes and HG handles (HG only by uiinspect
). A technical description of uiinspect
is provided here.
uiinspect
being used on Java, COM and Matlab handles:
checkClass
being used on a Java object or class-name:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With