When you write :

TestInterface i = () -> System.out.println("Hans");

You give an implementation to the void hans() method of the TestInterface.

If you could assign a lambda expression to an interface having more than one abstract method (i.e. a non functional interface), the lambda expression could only implement one of the methods, leaving the other methods unimplemented.

You can't solve it by assigning two lambda expressions having different signatures to the same variable (Just like you can't assign references of two objects to a single variable and expect that variable to refer to both objects at once).

Answer from Eran on Stack Overflow
🌐
Oracle
docs.oracle.com › javase › tutorial › java › javaOO › lambdaexpressions.html
Lambda Expressions (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
It follows that you can only use lambda expressions in situations in which the Java compiler can determine a target type: ... For method arguments, the Java compiler determines the target type with two other language features: overload resolution and type argument inference. Consider the following two functional interfaces ( java.lang.Runnable and java.util.concurrent.Callable<V>):
🌐
Baeldung
baeldung.com › home › java › core java › functional interfaces in java
Functional Interfaces in Java | Baeldung
March 26, 2025 - Not all functional interfaces appeared in Java 8. Many interfaces from previous versions of Java conform to the constraints of a FunctionalInterface, and we can use them as lambdas. Prominent examples include the Runnable and Callable interfaces that are used in concurrency APIs.
🌐
Baeldung
baeldung.com › home › java › lambda expressions and functional interfaces: tips and best practices
Lambda Expressions and Functional Interfaces: Tips and Best Practices | Baeldung
December 16, 2023 - Elegant Sort in Java 8 - Lambda Expressions go right past syntactic sugar and bring powerful functional semantics into Java. ... Functional interfaces, which are gathered in the java.util.function package, satisfy most developers’ needs in providing target types for lambda expressions and method references.
🌐
Medium
medium.com › @lakshyachampion › mastering-functional-interfaces-and-lambda-expressions-in-java-c02d8aaff5b2
Mastering Functional Interfaces and Lambda Expressions in Java | by Lakshya Agarwal | Medium
January 17, 2024 - Java provides several built-in ... lambda expressions were introduced in Java 8 as a way to provide concise syntax for expressing instances of single-method interfaces (functional interfaces)....
🌐
Stack Abuse
stackabuse.com › guide-to-functional-interfaces-and-lambda-expressions-in-java
Guide to Functional Interfaces and Lambda Expressions in Java
March 29, 2023 - Since a regular interface can have many abstract methods (and since there is no indication that this interface is not like any other), the compiler will blame the lambda expression for it tries to bind to a non-functional interface. To avoid this, Java provides a way to mark the interfaces that serve lambda expressions, explicitly:
🌐
W3Schools
w3schools.com › java › java_lambda.asp
Java Lambda Expressions
The lambda must match that method's parameters and return type. Java includes many built-in functional interfaces, such as Consumer (from the java.util package) used with lists.
🌐
InformIT
informit.com › articles › article.aspx
Lambda Expressions and Functional Interfaces | Java SE 8’s New Language Features, Part 1: Interface Default/Static Methods and Lambda Expressions | InformIT
A lambda expression (lambda) is a short-form replacement for an anonymous class. Lambdas simplify the use of interfaces that declare single abstract methods. Such interfaces are known as functional interfaces. ... Java 8 introduces a new FunctionalInterface annotation type that lets you annotate ...
Find elsewhere
🌐
Eherrera
eherrera.net › ocpj8-notes › 04-lambda-built-in-functional-interfaces
Java SE 8 Programmer II - Lambda Built-in Functional Interfaces
- Use the built-in interfaces included ... - Develop code that uses the UnaryOperator interface · Functional interfaces provide target types for lambda expressions and method references....
🌐
Sunflower Lab
thesunflowerlab.com › home › java lambda expressions
Java Lambda Expression - How To Implement Functional Interface
September 4, 2024 - In the above code, the snippet PerformCalculation interface is the functional interface. If you check Image 1 and Image 2, both will print 5. In image 2 we have used a Lambda Expression in lines 10 to 12.
🌐
GeeksforGeeks
geeksforgeeks.org › functional-interfaces-java
Java Functional Interfaces | GeeksforGeeks
December 27, 2024 - Runnable, ActionListener, and Comparator are common examples of Java functional interfaces. From Java 8 onwards, lambda expressions and method references can be used to represent the instance of ...
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › function › package-summary.html
java.util.function (Java Platform SE 8 )
3 weeks ago - The interfaces in this package are general purpose functional interfaces used by the JDK, and are available to be used by user code as well. While they do not identify a complete set of function shapes to which lambda expressions might be adapted, they provide enough to cover common requirements.
🌐
DZone
dzone.com › coding › java › functional interface and lambda expressions in java 8
Functional Interface and Lambda Expressions in Java 8
July 23, 2018 - Abstarct method in functionalInterface abstract double sayHello(); Lambda expression for abstract method will look like () -> (System.out.println(“Hellow”)) The () represents an empty input, and the response is String Hellow . The abstract method sum takes two inputs of type int . abstract method sum in functional interface abstract int sum(int a, int b); Lambda expression for abstract method will look like (a,b) -> (a+b) OR (int a,int b) -> (a+b)
🌐
Great Learning
mygreatlearning.com › blog › it/software development › streamlining code with functional interfaces and lambda expressions in java
Streamlining Code with Functional Interfaces and Lambda Expressions in Java
September 3, 2024 - It provides a way to represent a block of code as a single unit and pass it around to be executed at a later time. Lambda expressions are based on functional interfaces, which are interfaces that have a single abstract method.
🌐
Javatpoint
javatpoint.com › java-lambda-expressions
Java Lambda Expressions
October 16, 2016 - Java Java provides a new feature called method reference in Java 8. Method reference is used to refer method of functional interface. It is compact and easy form of lambda expression.
🌐
Credera
credera.com › en-us › insights › java-8-part-1-lamdas-streams-functional-interfaces
Java 8 Part 1 – Lambdas, Streams, and Functional Interfaces | Credera
March 15, 2024 - Java 8 will include a set of useful functional interfaces in the java.util.function package. Several important functional interfaces to note will be the Predicate, Supplier, and Consumer. Although functional interfaces alone do not add functionality, they will primarily be used by lambda ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › lambda-expressions-java-8
Java Lambda Expressions - GeeksforGeeks
Java lambda expressions, introduced in Java 8, allow developers to write concise, functional-style code by representing anonymous functions. They enable passing code as parameters or assigning it to variables, resulting in cleaner and more readable ...
Published   3 weeks ago
🌐
Medium
medium.com › @edward-heaver › lambda-expressions-and-functional-interfaces-how-java-makes-functions-first-class-citizens-2549950b7897
Lambda Expressions and Functional Interfaces — How Java makes functions first-class citizens | by Edward Heaver | Medium
July 10, 2022 - This is what tells the compiler that what it is dealing with is a lambda expression. The above example is an implementation of the Supplier Functional Interface. This is one of many different Functional Interfaces included in Java and is designed to allow the programmer to supply a value when invoked.