this and super are usable inside a lambda expression, but unlike in an anonymous inner class, they don't refer to the lambda itself — a lambda has no enclosing instance of its own, so both keywords resolve lexically to the enclosing class where the lambda is written.
Key Points: • Because lambdas don't introduce a new scope for this, using this inside a lambda gives you the instance of the surrounding class, exactly as if you'd referenced it just outside the lambda. • This is the opposite of an anonymous inner class, where this refers to the anonymous class instance itself, requiring Outer.this to reach the enclosing instance. • super inside a lambda likewise refers to the superclass of the enclosing class, letting a lambda call an inherited method via super.someMethod(). • This lexical scoping makes lambdas behave more predictably when mixed with object state, since there's no ambiguity about which "this" a lambda captures. • A lambda in a static context (a static method or static initializer) has no enclosing instance, so this cannot be used there at all — this applies to lambdas the same as ordinary code in that context.
Example: Inside an instance method of class Reporter, the lambda () -> this.generate() inside a Runnable field refers to the Reporter instance, not to some hidden lambda "instance" — printing this.getClass() from within the lambda would show Reporter, not a synthetic lambda class.
Code Example:
class Greeter {
String name = "Greeter";
Runnable greet() {
return () -> System.out.println(this.name); // 'this' is the Greeter instance
}
}Interview Tip: A concise interview answer is:
"Yes, you can use this and super inside a lambda, but they don't refer to the lambda — lambdas don't have their own instance context, so this refers to the enclosing class instance, and super refers to that class's superclass. This is different from an anonymous inner class, where this refers to the anonymous class itself, which is a common interview gotcha."