Question: Is there a way to write one function that would account for the different data types? Would generics work and if so how do you do that in AnyLogic?
Background: I have three different agent types that inherit from a parent class.
"agentB", "agentC", & "agentD" that inherit / extend from "agentA". They all have the same variables "condition1" and "condition2".
Additionally, I created populations of the above agents (in main) using database tables for initialization.
"popB", "popC", and "popD"
I am using the findFirst() function to find the first object that meets the required conditions. In order to account for the different types I wrote 3 separate functions that are the same except for the types.
Code Examples:
Function for AgentB Type:
AgentB curAgent = null;
curAgent = findFirst(main.popB, p->p.condition1 == true && p.condition2 == true);
return curAgent;
Function for AgentC Type:
AgentC curAgent = null;
curAgent = findFirst(main.popC, p->p.condition1 == true && p.condition2 == true);
return curAgent;
Function for AgentD Type:
AgentD curAgent = null;
curAgent = findFirst(main.popD, p->p.condition1 == true && p.condition2 == true);
return curAgent;