### Access a Java Class Static

To access a Java Class, make use of JavaObjects (requires the JavaObject library).
Below are some examples on how to access a Java Class from the Clojure API.
Reference: http://clojure.github.io/clojure/javadoc/clojure/java/api/Clojure.html
This class has no constructors (status 31-Jan-2015).
Class Clojure
java.lang.Object
clojure.java.api.Clojure
public class Clojure
Static Access to the Class Clojure
'Define the JavaObject and init for static access to the class
Dim oClojure As JavaObject
oClojure.InitializeStatic( "clojure.java.api.Clojure" )
Use Clojure's namespaces to locate an arbitrary var, returning the var's IFn interface.
'Some math examples
'Define the var IFn interface and the action
Dim oIFn As JavaObject
oIFn = oClojure.RunMethod( "var", Array As Object( "clojure.core", "+" ) )
'Run the function, idc +
Dim x As Float = oIFn.RunMethod( "invoke", Array As Object( 19, 58 ) )
Log(x)
'The same can be done with other functions, like -, *, /
oIFn = oClojure.RunMethod( "var", Array As Object( "clojure.core", "-" ) )
Dim x As Float = oIFn.RunMethod( "invoke", Array As Object( 19, 58 ) )
Log(x)
oIFn = oClojure.RunMethod( "var", Array As Object( "clojure.core", "*" ) )
Dim x As Float = oIFn.RunMethod( "invoke", Array As Object( 19, 58 ) )
Log(x)
oIFn = oClojure.RunMethod( "var", Array As Object( "clojure.core", "/" ) )
Dim x As Float = oIFn.RunMethod( "invoke", Array As Object( 19, 58 ) )
Log(x)
oIFn = oClojure.RunMethod( "var", Array As Object( "clojure.core", "/" ) )
Try
Dim x As Float = oIFn.RunMethod( "invoke", Array As Object( 19, 0 ) )
Log(x)
Catch
Log(LastException.Message)
End Try
Output:
Program started.
3
77
39
1102
0.32758620381355286
java.lang.ArithmeticException: Divide by zero

Changed: , Category: JavaObject, File: T6C208M1516.htm, ID: 1516