It's certainly possible to declare variables whose types are functional interfaces and then assign lambdas to them. That's the conclusion of this answer and its comment thread. For example, one might have a declaration like this:
BiFunction<Integer,Integer,Integer> add = (a, b) -> a + b;
This isn't exactly what the OP asked for. The Python equivalent of this would be something like:
add = lambda a, b: a + b
This isn't a named function; it's a variable whose value is a (lambda) function. The original question was asking about using named function in Java. The way to do this is with a method reference.
Suppose you have method that takes a BiFunction<Integer,Integer,Integer> parameter. You could pass it the add variable as defined above. But you could also declare an ordinary method, and use it as the target of a method reference. The trick is to make sure that the "shape" (number and type of arguments, type of return value) matches whatever functional interface you're trying to use. In this case you have two parameters of type Integer and the return value is Integer, so your method would be
static Integer add(Integer a, Integer b) {
return a + b;
}
Then you can refer to this using a method reference of the form MyClass::add.
Note that I've made this a static method. If it were an instance method, the receiver (this) is a hidden parameter that you have to take into account when matching it to a functional interface.
Note also that because of auto-boxing, one could also write:
static int add(int a, int b) {
return a + b;
}
There's certainly a use for assigning lambdas to variables, such as if the choice of an algorithm is made at runtime. But if the lambdas are all being assigned to constant fields, it's often easier to use method references that target ordinary methods.
YourClass::add?flatMap/mapto implementmapon two lists like in this Scala example: github.com/robertberry/… (and as others notedInteger::sumcan add them.)