Skip to content

import

path · scripts/path/import.m

: import PACKAGE.CLASS
: import PACKAGE.*
: import PACKAGE.CLASS1 PACKAGE.CLASS2 …

Import Java classes into the calling workspace.

import java.util.ArrayList
a = ArrayList ();                 % construct
ArrayList.valueOf (...)          % static method
import java.io.File java.util.Date

import java.util.*
m = HashMap ();                   % any class of the package, by short name

Each named class becomes a variable of that name in the calling workspace, so the short name works like the full java.util.ArrayList does (see javapackage). As in MATLAB the import lasts as long as that workspace. A wildcard import binds every public class of the package that does not clash with a variable already in the workspace.

Names that are not Java classes (MATLAB package imports) are not yet supported: they raise an error, except when running without graphics (batch), where they are ignored.