Wiki source for FunctionJnew


Show raw source

=====Function jnew=====

This function is part of the [[JavaObjects Java Objects]] support.

====Name====
**jnew** creates a Java Object


====Synopsis====
jnew( classname [args ...] )


====Description====

jnew creates an instance of a java object given its classname and optional constructor arguments.
The classname must be either in one of the packages in the global CLASSPATH or an [[CommandImport imported]] class.

If no additional arguments are provided then the default constructor for the class is used.
Otherwise a constructor matching the types of the supplied arguments is searched for and if found, invoked.
The result is the newly created java object.

Typical use would be to assign this object to a variable or to pass to a function or command.

Example: Create a java.util.Date object and print the unix time.

%%
import commands java
date=jnew(java.util.Date)
echo date.getTime()
%%

Result
%%
1290261981094
%%


Throws an exception if the class is not found or cannot be constructed.

----
[[Commands]]
[[Functions]]
[[JavaObjects Java Objects]]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki