Calling Java Constructors

Java constructors are called by using the function named new(). If there are several constructors, then again the system tries to find the one that is the best fit, according to the types of the supplied arguments. The result of calling new() is an XPath value whose type is denoted by a QName whose local name is the actual Java class (for example java.sql.Connection or java.util.List) and whose namespace URI is http://saxon.sf.net/java-type (conventional prefix jt). Any '$' characters in the Java class name are replaced by '-' characters in the QName, and for array types, any '[' characters at the start of the Java binary class name are replaced by '_-' (underscore then hyphen). So for example the QName representing the Java class byte[] (binary name [B) becomes Q{http://saxon.sf.net/java-type}_-B, while byte[][] (binary name [[B) becomes Q{http://saxon.sf.net/java-type}_-_-B.

The only things that can be done with a wrapped Java Object are to assign it to a variable, to pass it to an extension function, and to convert it to a string, number, or boolean, using the rules given below.

The use of external object types in namespace http://saxon.sf.net/java-type reflects the Java type hierarchy. For example, if a variable is declared to accept a type of jt:java.util.List, then a value of type jt:java.util.ArrayList will be accepted, but a value of type jt:java.util.HashMap will not.

In the XPath type hierarchy, external object types are a fourth kind of item, alongside nodes, atomic values, and functions. (In earlier Saxon releases, external object types were considered subtypes of xs:anyAtomicType, but this is no longer the case.)