MATLAB Answers

How to get the name of the calling class in a static method?

20 views (last 30 days)
Daniel
Daniel on 6 Oct 2014
Commented: Daniel on 7 Oct 2014
Hi,
is there a way so that a static method can get the name of the class that is calling it?
In a non-static method, one always has the option of running class(obj) obj being the object on whihc the method is being applied. But how to do it for a static method?

Accepted Answer

Guillaume
Guillaume on 6 Oct 2014
mfilename('class')
However, since inheritance doesn't really have any effect on static methods, you could just hardcode it in the method.
  5 Comments
Daniel
Daniel on 7 Oct 2014
Yes, it works, so I'll have to do it like this.
The calling syntax was actually important, as the idea is that the users of my package know the available class names and can find out through autocompletion the available methods accessible to the users. That's the standard setting in my system, but well. Sometimes one cannot avoid exceptions.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!