<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/instances-of-non-capturing-lambdas-nipafx-zaww2q71h" -->

---
title: Instances of Non-Capturing Lambdas // nipafx | daily.dev
description: Java's JVM makes no guarantee that each evaluation of a lambda expression produces a new object instance. Non-capturing lambdas (those that don't reference...
canonical: https://daily.dev/posts/instances-of-non-capturing-lambdas-nipafx-zaww2q71h
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Instances of Non-Capturing Lambdas // nipafx | daily.dev
og:description: Java's JVM makes no guarantee that each evaluation of a lambda expression produces a new object instance. Non-capturing lambdas (those that don't reference...
og:url: https://daily.dev/posts/instances-of-non-capturing-lambdas-nipafx-zaww2q71h
og:image: https://api.daily.dev/og/posts/ZAWw2q71H.png
og:image:alt: Instances of Non-Capturing Lambdas // nipafx
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Instances of Non-Capturing Lambdas // nipafx

**[nipafx \(Nicolai Parlog\)](https://daily.dev/sources/nipafx)** · 9 min read · 0 upvotes · 0 comments

## Summary

Java's JVM makes no guarantee that each evaluation of a lambda expression produces a new object instance. Non-capturing lambdas (those that don't reference external variables) can be — and in practice often are — reused as the same instance across multiple calls. This leads to a subtle bug: a factory method returning a non-capturing lambda may return the same object reference every time, causing unexpected behavior when identity matters (e.g., adding to a HashSet yields fewer elements than expected). The post explains the JLS specification behind this behavior, contrasts lambdas with anonymous classes (which always create new instances), and offers practical guidelines: avoid lambdas in factory methods, prefer anonymous or nested classes when identity matters, be cautious with default-method-based functional interfaces, and never rely on undocumented JVM behavior.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://nipafx.dev/java-non-capturing-lambdas>

## Similar posts on daily.dev

- [Feedback on checked exceptions and lambdas](https://daily.dev/posts/feedback-on-checked-exceptions-and-lambdas-t6mf4erty) · A Java geek · 0 upvotes · 0 comments
- [adam bien's blog](https://daily.dev/posts/adam-bien-s-blog-nwa7gwljx) · Adam Bien · 2 upvotes · 0 comments
- [C\+\+ Insights new lambda transformation](https://daily.dev/posts/c-insights-new-lambda-transformation-tbpwo3poh) · Andreas Fertig · 0 upvotes · 0 comments
- [Checked exceptions and lambdas](https://daily.dev/posts/checked-exceptions-and-lambdas-kqihxduxj) · A Java geek · 0 upvotes · 0 comments

---

Tags: [#java](https://daily.dev/tags/java)

[View this post on daily.dev](https://daily.dev/posts/instances-of-non-capturing-lambdas-nipafx-zaww2q71h)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Instances of Non-Capturing Lambdas // nipafx","url":"https://daily.dev/posts/instances-of-non-capturing-lambdas-nipafx-zaww2q71h","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/instances-of-non-capturing-lambdas-nipafx-zaww2q71h"},"datePublished":"2026-03-16T08:14:01.811Z","dateModified":"2026-03-16T08:27:20.908Z","description":"Java's JVM makes no guarantee that each evaluation of a lambda expression produces a new object instance. Non-capturing lambdas (those that don't reference...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/55708d7513bae2d9f667531a2886b805?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/55708d7513bae2d9f667531a2886b805?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"nipafx (Nicolai Parlog)","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"nipafx (Nicolai Parlog)","logo":"https://media.daily.dev/image/upload/s--H_Echo_u--/f_auto,q_auto/v1773648772/logos/nipafx?_a=BAMAMiiu0","url":"https://daily.dev/sources/nipafx"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/instances-of-non-capturing-lambdas-nipafx-zaww2q71h","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"java","timeRequired":"PT9M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"nipafx (Nicolai Parlog)","item":"https://daily.dev/sources/nipafx"},{"@type":"ListItem","position":3,"name":"Instances of Non-Capturing Lambdas // nipafx"}]}
```

