I’m porting a C# Library to Java (for nonlinear regression, original code here). The library uses the Func<> class, which doesn’t exist in Java. I.E. (A, B, C, and D, and time are parameters used for regression, don’t need fixed.)
Func<double>[] regressionFunctions = new Func<double>[]
{() => A * Math.Exp(time) * Math.Sin(B * time),
() => C * Math.Exp(time) * Math.Cos(D * time)};
What I would like to do is convert this to Java code. I saw something about creating an anonymous inner class, but I’m not certain of the correct usage for this particular situation. I would like the equation to be evaluable at a later time (for a particular value of t). Do I need a new class, an interface, or what would be the best method?
Any help would be appreciated! Thanks in advance.
You can define your own interface, and use anonymous implementations to port the code:
In order for the implementation to work,
A,B,C,D, andtimevariables must be either instance/class variables, or befinallocal variables.