Changes

Jump to navigation Jump to search
344 bytes added ,  13:27, 27 April 2012
=Namespace Declarations=
Java classes can be declared via namespaces. The namespace can then be used tocall static functions contained in that class. The following example uses Java’s {{Mono|Math}} class to return the cosine of an angleby calling the static method {{Mono|cos()}}: <pre class="brush:xquery">declare namespace math = "java:java.lang.Math";math:cos(xs:double(0))The </pre> As an alternative, the [[XQuery 3.0#Expanded QNames|Expanded QName]] notation is used to address the{{Mono|cos()}} method, which can be applied to directly called, as it is specify a {{Mono|static}} methodnamespace URI instead of the prefix:
<pre class="brush:xquery">
Q{java:java.lang.Math}cos(xs:double(0))
</pre>
The next constructor of a class can be invoked by calling the virtualfunction {{Mono|new()}}. Instance methods can then called bypassing on the resulting Java object as first argument. The following example writes 256 bytes to the file {{Mono|output.txt}}.First, a new {{Mono|FileWriter}} instance is created: by calling the, and its{{Mono|newwrite()}} function, the class constructor is invoked. Instancemethods are called by passing on in the resulting Java object asfirst argumentnext step:
<pre class="brush:xquery">declare namespace fw = "java.io.FileWriter";
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu