next up previous contents index
Next: Sections Up: Multiarrays Previous: Syntax   Contents   Index

Some Semantic Issues

Multiarrays can have any rank greater than or equal to zero. Their elements can have any standard Java type including primitive types, class types, and Java array types. They cannot, however, have multiarray type: multiarrays of multiarrays are specifically disallowed.

For multiarrays with elements of non-primitive type, conversions between multiarrays are allowed, completely analogous to the corresponding conversions between Java arrays. For example, a method with declaration:

\begin{minipage}[t]{\linewidth}\small\begin{verbatim}void foo(Object [[*,*]] a) ;\end{verbatim}\end{minipage}\end{displaymath}

accepts as argument any rank-two multiarray whose elements have Java reference type. So this would be legal:

\begin{minipage}[t]{\linewidth}\small\begin{verbatim}Goo [[*,*]] b ;
foo(b) ;\end{verbatim}\end{minipage}\end{displaymath}

where Goo is the name of some class (or interface). These conversions exist only between multiarrays of the same rank. No conversion between a multiarray of rank $R$ and a multiarray of different rank is possible.

In many respects multiarray types behave like Java reference types. A variable of multiarray type always holds a reference to a multiarray (or a null reference). In this example:

... [[N, N]] ;float [[*,*]] q = r ;\end{verbatim}\end{minipage}\end{displaymath}

q and r become two references to the same multiarray. Of course this is similar to the situation with Java arrays. Garbage collection for multiarrays operates on similar lines to the standard Java case.

Technically however, a multiarray reference is not equivalent to a Java reference. Multiarray references and Java references are not interconvertible. If the method foo had been declared instead as

\begin{minipage}[t]{\linewidth}\small\begin{verbatim}void foo(Object a) ;\end{verbatim}\end{minipage}\end{displaymath}

then it would not be allowed to pass a multiarray as its argument. One consequence is that a reference to a multiarray cannot directly be stored in an instance of a Java container class like java.util.ArrayList or java.util.HashMap, because those classes accept entries of type Object.

There is another related limitation in this mold: one cannot declare standard Java arrays with elements of multiarray type.

These limitations (which exist to simplify the translation scheme) may be slightly inconvenient, but they are not a serious obstacle in practice. One can declare classes with fields of multiarray type. So the user can create a wrapper class for any particular multiarray type. A wrapper object, containing a multiarray, can then be stored in an instance of a container class or a Java array.

To summarize part of this discussion: multiarrays of Java arrays are allowed; Java arrays of multiarrays are not allowed (while multiarrays containing objects as elements, and objects containing multiarrays as fields, are both allowed).

next up previous contents index
Next: Sections Up: Multiarrays Previous: Syntax   Contents   Index
Bryan Carpenter 2003-04-15