Lambda: this inside a lambda refers to the enclosing instance

A lambda has no instance of its own, so this inside its body resolves to the object that was executing when the lambda was created, exactly as if the lambda's code were written inline.

Code
class Reporter {
    String name = "reporter";
    Runnable asLambda() {
        return () -> System.out.println("Lambda this.name: " + this.name);
    }
}
new Reporter().asLambda().run();
Output
Lambda this.name: reporter
Advertisement
More in JAVA

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-09-27

© Java Coding Hub · About · Contact · Privacy · Terms