MATLAB: Does “requiredF​ilesAndPro​ducts” not list the callback as a requirement if it is specified as a character vector

callbackMATLABpragmarequiredfilesandproducts

We are using the codetools function requiredFilesAndFolders to produce our project file at compile time which works well. Unfortunately it does not detect callback functions in one case. When the callback is declared using the syntax
set(myButton, 'Callback', 'myPackage.myFunction(''myParam'')')
then "myFunction" is not listed as a requirement:
>> matlab.codetools.requiredFilesAndProducts('myApp.m')'
2×1 cell array
{'myPath\myApp.m'}
{'myPath\myApp.fig'}
However, if we use the syntax
set(myButton, 'Callback', @() myPackage.myMethod(''myParam'') )
then "myMethod" is listed as a requirement:
>> matlab.codetools.requiredFilesAndProducts('myApp.m')'
3×1 cell array
{'myPath\myApp.m'}
{'myPath\myApp.fig'}
{'myPath\+myPackage\myFunction.m'}
Why this difference and why is it not explained in the documentation page for "requiredFilesAndProducts"?

Best Answer

Unfortunately if a callback is specified as a character vector, then "requiredFilesAndProducts" is not able to find that dependency. However, the callback will be found as a dependency if it is specified as a function handle.
It is advised to always specify callbacks as function handles. Specifying callbacks as character vectors or strings is supported, but not recommended.
You can read about this at the following documentation link:
However, if you are adamant about specifying the callback as a character vector, you can always use a "pragma function" directive in "myApp.m" to force a dependency to "myPackage.myFunction.m". To include this directive, you can modify "myApp.m" as follows:
function varargout = myApp(varargin)
%#function myPackage.myFunction
% the rest of the function goes here.
You can read more about "pragma function" directives at the following documentation link: