JAVA interfaces in AnyLogic

You can add custom JAVA interfaces to AnyLogic models.

Defining JAVA interfaces in AnyLogic

Proceed as follows if you want to add a customer JAVA interface to your AnyLogic model:

  • Go to the Projects view
  • Right click the model
  • In the menu select New, and then Java Interface…
  • You will be prompted to specify the name of the new JAVA interface
  • Specify the name and click Finish
  • The AnyLogic JAVA coding editor will open
  • Define the interface in the coding editor

Implementing JAVA interface in AnyLogic

If you have already added an interface to your AnyLogic you can implement it in a JAVA class. You do so by specifying the body of the methods defined in the interface.

There are two ways in which you can implement an interface in Anylogic:

  1. Implement the interface in a new JAVA class, adding it to the AnyLogic model
  2. Implement the interface in an agent class

Implement interface in JAVA class

Select the desired class in the Project overview and open it by double-clicking the class. The Java coding editor will open in AnyLogic. Add the “implements” keyword, followed by the interface name, right after the class definition. E.g. public class TestClass implement TestInterface{…}.

Implement interface in agent class

Select desired agent type in the Project overview. Access the “Advanced Java” section. Go the Properties view. Find the Implements field and enter all interface names here, separated by comma.