In Java do Action Listeners give similar functionality to Delegates? I don't do much Java either besides what was required in some undergrad classes.
I've recently migrated from C++ to C# for all my personal and work projects when I can use it. I will NEVER go back to C++ ... C# is that much better.
BTW, I'm using Delegates to speed up some C# Neural Network code that must be executed 100's of time per frame in game. Each node in the network is assigned a random mathematical function, from out of approximately 15 functions. Each network has possibly dozens of nodes, and there are a lot of networks.
Instead of a switch of if-else at each node like this ...
Code:
switch(functionNumber)
{
case 0: Sin();
case 1: Cos();
case 2: HyperbolicTangent();
case 3: Inverse();
case 4: Ramp();
case 5: Step();
case 6: Gaussian();
case 7: Spike();
case 8: Tangent();
etc...
}
... each node gets assigned a Delegate called "functionPointer" that points to it's correct function. So the above switch statement within a node is replaced by simply:
Code:
node.functionPointer();
So, because nodes get activated 100's of times per frame, possibly thousands of 'switch' cases per frame are avoided, resulting in significant speedup.