|MATLAB Function Reference|
Add a package or class to the current Java import list for the MATLAB command environment or for the calling function
import adds all the classes in
package_name to the current import list. Note that
package_name must be followed by
import adds a single class to the current import list. Note that
class_name must be fully qualified (that is, it must include the package name).
import adds all named classes and packages to the current import list. Note that each class name must be fully qualified, and each package name must be followed by
with no input arguments displays the current import list, without adding to it.
L = import
with no input arguments returns a cell array of strings containing the current import list, without adding to it.
The import command operates exclusively on the import list of the function from which it is invoked. When invoked at the command prompt,
import uses the import list for the MATLAB command environment. If
import is used in a script invoked from a function, it affects the import list of the function. If
import is used in a script that is invoked from the command prompt, it affects the import list for the command environment.
The import list of a function is persistent across calls to that function and is only cleared when the function is cleared.
To clear the current import list, use the following command.
This command may only be invoked at the command prompt. Attempting to use
import within a function results in an error.
The only reason for using
import is to allow your code to refer to each imported class with the immediate class name only, rather than with the fully qualified class name.
import is particularly useful in streamlining calls to constructors, where most references to Java classes occur.
This example shows importing and using the single class,
java.lang.String, and two complete packages,