External Interfaces/API Reference    
import

Add a package or class to the current Java import list for the MATLAB command environment or for the calling function

Syntax

Description

import package_name.* adds all the classes in package_name to the current import list. Note that package_name must be followed by .*.

import class_name 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 cls_or_pkg_name1 cls_or_pkg_name2... 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 .*.

import 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 clear import within a function results in an error.

Remarks

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.

Examples

This example shows importing and using the single class, java.lang.String, and two complete packages, java.util and java.awt.

See Also
clear


  class isa