As the title says, I am looking to implement some very short methods of a class using lambdas, nothing unheard of.
Python can do it, C# can do it, and to some extent i believe even C++ can do it now.
But I am trying to do the same with a Java class with no success, I looked up anything that might answer this particular question with no luck. I would rather not cluster my application with 100 functional interfaces just to be able to use lambdas for the more trivial functions or methods as that would kind of defeat the purpose of writing less code.
Here is what I did try(obviously, none of them worked, the second one came close as it at least recognized the fact that a lambda was there:
import static java.lang.Math.*;
class Main {
static double log = (double val, double base) -> Math.log(val) / Math.log(base); // First try. Python way.
static double log = (val, base) -> Math.log(val) / Math.log(base); // Second try. Also inspired from the
// Python way, somewhat similarly to the
// F# or haskell way.
static double log(double val, double base) -> Math.log(val) / Math.log(base); // Third try. The C# way.
public static void main(String[] argv){
System.out.println(log(8,2));
}
}