I just discovered that when calling Java from Matlab
object.method(arg1,...,argn)
is equivalent to
method(object, arg1,...,argn)
The problem here is I also have a method.m
that does some translation from Java to Matlab (eg. convert String[]
to cell of strings). My method.m
looks like
function result = method(object, arg1,...argn)
intermediate = object.method(arg1,...argn);
result = translate(intermediate);
What is happening is when I call method(object, arg1,...,argn)
, it does the direct Java call, instead of my using my method.m
The fix is easy, just don't use the same method name for both my Java methods and my .m
files. But is there another way? How do I know which method will be called given the same name? Is there a way to ensure I call method.m
instead of the Java method? Its easy to ensure a call to the Java method, just use the object.method
syntax.
As a side note, what is also silly is the .m
Editor links to the method.m
on the method(object, arg1,...,argn)
call, while when it debugs it calls the Java method.