javaConstructor( cName, pType... )

Returns a function that constructs an instance of the specified Java class cName. The actual contstructor that is called is identified by the parameter types pType.... The class name cName is specified as a string containing the fully qualified class name, while the parameter types are specified as strings containing the fully qualified class name or primitive type of the parameter.

Consider the following example, which imports the constructor for the Java URL class. We import the version of the constructor taking four parameters, the protocol, host, port and file:

:-) var newJavaURL = javaConstructor(
:-)   "java.net.URL",
:-)   "java.lang.String",
:-)   "java.lang.String",
:-)   "int",
:-)   "java.lang.String"
:-) );
There are 0 results
      

The javaConstructor function returns a function which is assigned to the newJavaURL variable. We can now use this function to construct a instance of the java.net.URL class, e.g.

:-) newJavaURL( "http", "www.sourceforge.net", 80, "/projects/millscript/" );
There is 1 result
http://www.sourceforge.net:80/projects/millscript/
      

We can check that the returned object is an instance of the correct class by assigning it to a variable and using the className function to identify it, e.g.

:-) var url = newJavaURL( "http", "www.sourceforge.net", 80, "/projects/millscript/" );
There are 0 results
:-) url.className;
There is 1 result
`java.net.URL`