Lambda expressions are only usable with functional interface as said by Eran but if you really need multiple methods within the interfaces, you may change the modifiers to default or static and override them within the classes that implement them if necessary.

public class Test {
    public static void main(String[] args) {
        I1 i1 = () -> System.out.println(); // NOT LEGAL
        I2 i2 = () -> System.out.println(); // TOTALLY LEGAL
        I3 i3 = () -> System.out.println(); // TOTALLY LEGAL
    }
}

interface I1 {
    void show1();
    void show2();
}

interface I2 {
    void show1();
    default void show2() {}
}

interface I3 {
    void show1();
    static void show2 () {}
}

Inheritance

You shouldn't forget the inherited methods.

Here, I2 inherits show1 and show2 and thus can not be a functional interface.

public class Test {
    public static void main(String[] args) {
        I1 i1 = () -> System.out.println(); // NOT LEGAL BUT WE SAW IT EARLIER
        I2 i2 = () -> System.out.println(); // NOT LEGAL
    }
}

interface I1 {
    void show1();
    void show2();
}

interface I2 extends I1 {
    void show3();
}

Annotation

To make sure your interface is a functional interface, you may add the following annotation @FunctionalInterface

@FunctionalInterface <------- COMPILATION ERROR : Invalid '@FunctionalInterface' annotation; I1 is not a functional interface
interface I1 {
    void show1();
    void show2();
}

@FunctionalInterface
interface I2 {
    void show3();
}
Answer from Yassin Hajaj on Stack Overflow
Top answer
1 of 4
37

Lambda expressions are only usable with functional interface as said by Eran but if you really need multiple methods within the interfaces, you may change the modifiers to default or static and override them within the classes that implement them if necessary.

public class Test {
    public static void main(String[] args) {
        I1 i1 = () -> System.out.println(); // NOT LEGAL
        I2 i2 = () -> System.out.println(); // TOTALLY LEGAL
        I3 i3 = () -> System.out.println(); // TOTALLY LEGAL
    }
}

interface I1 {
    void show1();
    void show2();
}

interface I2 {
    void show1();
    default void show2() {}
}

interface I3 {
    void show1();
    static void show2 () {}
}

Inheritance

You shouldn't forget the inherited methods.

Here, I2 inherits show1 and show2 and thus can not be a functional interface.

public class Test {
    public static void main(String[] args) {
        I1 i1 = () -> System.out.println(); // NOT LEGAL BUT WE SAW IT EARLIER
        I2 i2 = () -> System.out.println(); // NOT LEGAL
    }
}

interface I1 {
    void show1();
    void show2();
}

interface I2 extends I1 {
    void show3();
}

Annotation

To make sure your interface is a functional interface, you may add the following annotation @FunctionalInterface

@FunctionalInterface <------- COMPILATION ERROR : Invalid '@FunctionalInterface' annotation; I1 is not a functional interface
interface I1 {
    void show1();
    void show2();
}

@FunctionalInterface
interface I2 {
    void show3();
}
2 of 4
14

Lambda expressions can only be used to implement functional interfaces, which are interfaces having a single abstract method. An interface with two abstract methods can't be implemented by a lambda expression.

🌐
Sunflower Lab
thesunflowerlab.com › home › java lambda expressions
Java Lambda Expression - How To Implement Functional Interface
September 4, 2024 - It is used for implementing the functional interface. An Interface with only one abstract method is called a functional interface. A “@FunctionalInterface” annotation is used to indicate a functional interface.
Discussions

java - Why do I need a functional Interface to work with lambdas? - Stack Overflow
If you are just thinking about ... is, that they are not supposed to be an interface implementation helper. →Lambda expressions are functions. The functional interfaces are just a vehicle to add them to Java without changing the type system, not their purpo... More on stackoverflow.com
🌐 stackoverflow.com
[Java] Can someone explain how interfaces work with arrow functions?
Essentially, in order to be a functional interface, the interface needs to have just one method. That's the rule. The reason is, I assume, because without that it would be impossible to know what method you want your anonymous function to invoke (without additional annotation). This: ()->System.out.println("Not from thing") says "A function with no arguments that prints out blah blah blah" and then you pass that touseInterface that expects a whole interface. If there are two method declared in the interface then which one does that lambda implement? There's no way to know. If, however, there is just one method in the interface (as is the case) then that anonymous function must be intended to implement that method. More on reddit.com
🌐 r/learnprogramming
5
2
September 12, 2022
How does Java type check a program containing lambda expressions and default methods?
What makes you think that lambda expressions are not type-checked at compile time? Lambda expressions have to conform to some functional interface and this is used in the type inference process. I’m not sure how default methods make this any harder. As long as an interface has exactly one abstract method, it’s a functional interface. The existence of default methods is honestly no different than defining static methods whose first argument is an instance of the interface. More on reddit.com
🌐 r/java
17
5
July 10, 2023
Why does the List interface have forEach, but not map?
why isn't every List a Stream? To answer this part of the question, it's because a stream is a fundamentally different datatype than a list. A list represents a collection of data, while a stream represents a pipeline for processing data. Streams can only be processed once, and are designed to perform multiple operations on some provided data. They don't store any intermediate results, and then do lazy processing once you specify a terminal operator (like toList() or forEach()). For example, if you had something like this: Stream a = List.of(1, 2, 3).stream(); Stream b = a.filter(n -> n > 1); Stream c = b.map(n -> String.valueOf(n)); List d = c.toList(); This is functionally identical to this: List d = List.of(1, 2, 3).stream() .filter(n -> n > 1) .map(n -> String.valueOf(n)) .toList(); If you inspected b, however, it would not contain any data about what elements were remaining, because the stream has not executed yet. Assigning the various steps of the stream along the way doesn't actually DO anything to the data, it just creates pointers to instances of the pipeline. As mentioned before, the pipeline can only be executed once, which means a stream is consumed when you perform a terminal operation on it. It also can't be executed if you chain it to another pipeline. If, in the example above, you tried to do b.toList(), you'd get an IllegalStateException, because b was already operated on. If you did c.toList(), you'd get a list of "2", "3". If you did c.toList() a second time, you'd once again get an IllegalStateExcecution, because c has already been consumed. The intermediate operators like map actually do nothing except modify the pipeline definition until you call toList at the end. Once you execute toList, then the pipeline operates in a lazy way, evaluating the data elements one at a time. So, to recap: List: collection of ordered data Stream: an operation pipeline definition More on reddit.com
🌐 r/java
90
121
October 26, 2024
People also ask

What is a lambda expression in Java?
A lambda expression in Java is a short, anonymous block of code that implements a single-method (functional) interface. It lets you pass behaviour as an argument: instead of writing a verbose anonymous inner class, you write (params) -&gt; body. Lambdas were introduced in Java 8 (2014) and are still the standard way to work with Stream, Comparator, Runnable, and the java.util.function interfaces in modern Java (verified on JDK 25).
🌐
brilworks.com
brilworks.com › blog › lambda-expression-java
Lambda Expressions in Java: Syntax & Examples (2026 Guide)
What is the syntax of a Java lambda expression?
The syntax is (parameters) -&gt; expression for a single expression, or (parameters) -&gt; { statements; return value; } for a block body. Parentheses are optional with a single inferred-type parameter (x -&gt; x * 2); they are required for zero parameters (() -&gt; 42) or multiple parameters ((a, b) -&gt; a + b). The compiler infers parameter types from the target functional interface.
🌐
brilworks.com
brilworks.com › blog › lambda-expression-java
Lambda Expressions in Java: Syntax & Examples (2026 Guide)
How do method references work in Java?
A method reference is shorthand for a lambda that just calls an existing method. The four forms are: static (Integer::parseInt), bound instance (System.out::println), unbound instance (String::toLowerCase), and constructor (ArrayList::new). The compiler converts the reference to a lambda whose signature matches the target functional interface, so list.forEach(System.out::println) is equivalent to list.forEach(x -&gt; System.out.println(x)) but reads as the operation, not the plumbing.
🌐
brilworks.com
brilworks.com › blog › lambda-expression-java
Lambda Expressions in Java: Syntax & Examples (2026 Guide)
🌐
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 - So far, the lambda expressions were ascribed to an interface. This will be the norm any time we want to implement first-class functions in Java.
🌐
Jenkov
jenkov.com › tutorials › java-functional-programming › functional-interfaces.html
Java Functional Interfaces
March 8, 2021 - A Java functional interface can be implemented by a Java Lambda Expression.
🌐
Oracle
oracle.com › java › technical details
Trying Out Lambda Expressions in the Eclipse IDE - Java
Lambda expressions, also called closures, are a short-form replacement for anonymous classes. Lambda expressions simplify the use of interfaces that declare a single abstract method, which are also called functional interfaces. In Java SE 7, a single method interface can be implemented with one ...
🌐
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 ... scenarios ... In Java, lambda expressions were introduced in Java 8 as a way to provide concise syntax for expressing instances of single-method interfaces (functional interface...
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › java › match-lambdas-to-interfaces-in-java
Match Lambdas to Interfaces in Java - GeeksforGeeks
July 23, 2025 - Lambda expression only works with functional interfaces in java. Lambda expression provides a clear and concise way to represent a method interface via an expression. It provides the implementation of a functional interface and simplifies software ...
🌐
Oracle
docs.oracle.com › javase › tutorial › java › javaOO › lambdaexpressions.html
Lambda Expressions (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
You can specify this action with a lambda expression. Suppose you want a lambda expression similar to printPerson, one that takes one argument (an object of type Person) and returns void. Remember, to use a lambda expression, you need to implement a functional interface.
🌐
FavTutor
favtutor.com › blogs › lambda-expressions-java
Lambda Expression in Java 8: Example, Advantages & Code
December 12, 2022 - They are like functions that take arguments and do some functionality and return the corresponding value. Lambda expressions don't need a name and can be implemented in the body of the method itself.
🌐
Brilworks
brilworks.com › blog › lambda-expression-java
Lambda Expressions in Java: Syntax & Examples (2026 Guide)
June 9, 2026 - A lambda expression in Java is a short, anonymous block of code that implements a single-method (functional) interface. It lets you pass behaviour as an argument: instead of writing a verbose anonymous inner class, you write (params) -> body.
Price: $$
Address: 503, Fortune Business Hub, Science City Road, Sola, 380060, Ahmedabad
🌐
DZone
dzone.com › coding › java › functional interface and lambda expressions in java 8
Functional Interface and Lambda Expressions in Java 8
July 23, 2018 - An important point to remember is that the functional interface can have a number of default methods but only one abstract method. Lambda expressions are introduced in Java 8, and they can represent the instance of a functional interface.
🌐
Medium
shiharadilshan.medium.com › java-lambda-expressions-and-functional-interfaces-c6ac060e19d9
Java Lambda expressions and Functional interfaces. | by Shihara Dilshan | Medium
July 28, 2023 - How a functional interface is different than a normal interface? The main difference is you can you Lambda to instantiate a functional interface. That means you don’t need a concrete class to implement the functional interface.
🌐
To The New
tothenew.com › home › functional interface for lambda expressions : java 8
Functional Interface for Lambda expressions : Java 8 | TO THE NEW Blog
June 5, 2017 - The default behaviour of Lambda expressions is to accept only those interfaces as reference variables which have only one abstract method. We call such interfaces Functional Interfaces.
🌐
Cs1302uga
cs1302uga.github.io › cs1302-book › java › lambda › functional-interfaces.html
11.2. Functional Interfaces - CSCI 1302
If an interface in Java is considered a functional interface, then an alternative two-step process can be used to implement and utilize it using Java's lambda expression syntax:
🌐
TutorialsPoint
tutorialspoint.com › how-can-we-use-lambda-expressions-with-functional-interfaces-in-java
How can we use lambda expressions with functional interfaces in Java?
July 10, 2020 - The lambda expressions are anonymous functions and don't have any return type, access modifier and not belonging to any class. It can be used to simplify the implementation of the abstract method in a functional interface.
🌐
SWTestAcademy
swtestacademy.com › home › lambda functions in java and custom functional interfaces
Lambda Functions in Java and Custom Functional Interfaces
October 10, 2021 - Here, we call testPlay() method two times, for the first one we send a lambda function that has an upper-case functionality, and the second one has a lower-case functionality. Let’s do one more example. Assume that we have a shopping cart and we have a CartAction interface with the apply method. @FunctionalInterface public interface CartAction { void apply(String message, boolean isExist); } We will implement this apply method with several lambda functions like addItem, deleteItem, deleteCart.
🌐
Educative
educative.io › blog › java-lambda-expression-tutorial
Java lambda expression tutorial: Functional programming in Java
Before Java 8, we had to create an inner anonymous class to use these interfaces. ... Lambda expressions can only implement functional interfaces, which is an interface with only one abstract method.
🌐
Mistermicheels
learning-notes.mistermicheels.com › lambda expressions
Lambda expressions (Java) | learning-notes - mistermicheels
January 31, 2022 - So, does this mean that lambda expressions violate the rule that interfaces cannot be directly instantiated? Answer: no! When you write a lambda expression, Java uses that to create an instance of some class that implements the relevant functional interface
🌐
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 - Lambda expressions are a key feature introduced in Java 8 that allows us to write more concise and expressive code by representing a functional interface implementation in a more compact form.