Jess Information

Jess Home
Jess 7 Features
Download Now!
Online Demo

Documentation
FAQ
Manual
Mailing List
Jess Wiki

More information Related Web Sites
User Contributions
JSR94 Info
Developer's Log
About This Site

JESS ®, the Rule Engine for the JavaTM Platform

Jess Wiki: Using Jess With Java5

Some ideas for using Jess with Java 5 features.



I received a private email asking if Jess could work with Java 5 enumerated types. There's no specific code to deal with them, but I wondered if the existing "static import" feature would work. It turns out that it does. I wrote this Java enum class:


  public enum MyEnum {
    FOO, BAR, BAZ;
  }

Then in Jess 7, I tried this:

  Jess> (import MyEnum)
  TRUE
  Jess> (MyEnum.FOO)
  <Java-Object:MyEnum>
  Jess> (eq (MyEnum.FOO) (MyEnum.BAR))
  FALSE
  Jess> (eq (MyEnum.FOO) (MyEnum.FOO))
  TRUE
So importing an enum class EnumName will make the values available as the functions (EnumName.FOO), (EnumName.BAR), etc.

See BindEnumUserFunction for an alternative technique that maps enum constants to Jess variables. As this function also returns a list of all the enum constant objects, it can be used in the allowed-values clause of a slot entry in a deftemplate construct.


Front Page | Sandbox | Recent Changes | Powered by Friki | Last Edited: 02 April 2008