Java syntax like "DefaultEdge.class" is (more or less) just syntactic sugar for 
'java.lang.Class.forName("org.jgrapht.graph.DefaultEdge");' which in Jess will 
come out like "(Class.forName org.jgrapht.graph.DefaultEdge)"  (taking 
advantage of the default static imports from the java.lang package.) So you 
want to do something like

    (bind ?edge-class (Class.forName org.jgrapht.graph.DefaultEdge))
    (bind ?graph (new org.jgrapht.graph.DefaultDirectedGraph ?edge-class))

From: [] On 
Behalf Of Aurélien Mazurie
Sent: Wednesday, August 07, 2013 7:11 PM
To: jess-users
Subject: JESS: [EXTERNAL] Issue with static methods (or generics?)

Dear Jess users,
I am having trouble instantiating a Java class from within a rule's RHS, and 
cannot figure out how to solve this problem.

The code in my RHS creates an instance of a class from the JGraphT library. As 
seen in
 (lines 91-92), the creation of a DefaultDirectedGraph instance require another 
class as argument; here, DefaultEdge.

I couldn't find an example in the Jess documentation about how to do that. For 
example, I tried the following:

            (bind ?edge-class org.jgrapht.graph.DefaultEdge)
            (bind ?graph (new org.jgrapht.graph.DefaultDirectedGraph 

I also tried variations such as

            (bind ?edge-class org.jgrapht.graph.DefaultEdge)
            (bind ?graph (new org.jgrapht.graph.DefaultDirectedGraph 
(?edge-class getClass))


            (bind ?edge-class (new org.jgrapht.graph.DefaultEdge))
            (bind ?graph (new org.jgrapht.graph.DefaultDirectedGraph 

Any idea about what the syntax should be to properly instantiate the 
DefaultDirectedGraph class? For information (but not certain how relevant it is 
here), I succeeded in the past in using java.util.regex.Pattern and its static 
method 'compile' by typing

            (bind ?pattern-class java.util.regex.Pattern)
            (bind ?matches ((?pattern-class compile "...") matcher ?string))


Reply via email to