The question is in title. I need to automatically create Agent when model starts, and I need this Agent became static. If this type of Agent was a standart Java class I'll make it's static and create it with standart Java code:
MyClass myClass = new MyClass();
But I need to do this things with Anylogic agent.
The question is in title. I need to automatically create Agent when model starts, and I need this Agent became static. If this type of Agent was a standart Java class I'll make it's static and create it with standart Java code:
MyClass myClass = new MyClass();
But I need to do this things with Anylogic agent.
Share Improve this question edited Mar 3 at 18:21 Benjamin 12.8k4 gold badges19 silver badges33 bronze badges asked Mar 3 at 13:51 YuraYura 292 bronze badges 1- pls only use the anylogic tag, else you confuse 1000s of SOF users :) – Benjamin Commented Mar 3 at 18:22
1 Answer
Reset to default 1You cannot instantiate anything static, that is the definition of static in Java.
Your example code also does not instantiate a static MyClass
(but a non-static instance of MyClass).
In order to create agent objects dynamically (instantiate them), you can simple create an event at time 0 to MyAgent newAgent = new MyAgent();
The better approach is to add the agent directly into an existing population using myPop.add_MyAgent();
PS: If you truly want to use static
elements, you may need to brush up some OOP and Java first :) But I think you did not mean that, you want to instantiate an agent dynamically at runtime, right?