If you are not sure if the website you would like to visit is secure, you can verify it here. Enter the website address of the page and see parts of its content and the thumbnail images on this site. None (if any) dangerous scripts on the referenced page will be executed. Additionally, if the selected site contains subpages, you can verify it (review) in batches containing 5 pages.
favicon.ico: nipafx.dev/java-var-intersection-types - Unlocking Intersection Types W.

site address: nipafx.dev/java-var-intersection-types redirected to: nipafx.dev/java-var-intersection-types

site title: Unlocking Intersection Types With var // nipafx

Our opinion (on Wednesday 15 July 2026 11:52:39 UTC):

GREEN status (no comments) - no comments
After content analysis of this website we propose the following hashtags:


Hashtags existing on this website:




Meta tags:
description=Java 10 s var makes intersection types in Java more approachable. Generics tricks are still needed, but var makes it easy to declare such variables.;
keywords=intersection types;

Headings (most frequently used words):

intersection, types, with, declaring, unlocking, var, what, are, just, create, new, interface, generics, variables, of, reflection,

Text of the page (most frequently used words):
java (47), the (43), you (35), and (33), elements (28), #intersection (27), that (26), iterator (25), types (24), closeable (23), with (21), type (20), can (20), var (19), empty (17), project (16), string (14), scanner (14), new (14), this (13), but (13), firstmatch (12), createcloseableiterator (12), code (11), optional (11), what (11), generics (10), declare (9), not (9), variables (8), your (8), all (8), need (8), method (7), dollarword (7), works (7), for (7), interface (7), them (6), there (6), use (6), without (6), system (6), startswith (6), static (6), return (6), variable (6), want (6), declaring (6), create (6), stream (6), license (5), first (5), are (5), reflection (5), just (5), compile (5), has (5), needs (5), post (5), junit (5), still (4), like (4), work (4), have (4), they (4), way (4), out (4), ioexception (4), throws (4), how (4), because (4), parameter (4), extends (4), does (4), pretty (4), next (4), easy (4), condition (4), closeableiterator (4), about (4), try (4), some (4), community (4), even (3), while (3), generic (3), now (3), such (3), boolean (3), readandprint (3), straight (3), forward (3), though (3), would (3), really (3), doesn (3), local (3), get (3), implements (3), both (3), example (3), which (3), super (3), predicate (3), declaration (3), also (3), implement (3), libraries (3), contains (3), follow (3), share (3), blog (3), unlocking (3), pioneer (3), demos (3), streams (3), core (3), clean (3), privacy (2), rss (2), stackoverflow (2), github (2), twitch (2), youtube (2), discord (2), mastodon (2), bluesky (2), situation (2), support (2), being (2), makes (2), much (2), more (2), already (2), time (2), tool (2), simple (2), other (2), jvm (2), class (2), complicated (2), non (2), trivial (2), using (2), where (2), solution (2), their (2), its (2), methods (2), having (2), callers (2), println (2), void (2), after (2), actually (2), better (2), too (2), far (2), neither (2), nor (2), look (2), another (2), syntax (2), compiles (2), passed (2), private (2), instance (2), syntactically (2), these (2), two (2), allow (2), bounded (2), over (2), well (2), findany (2), filter (2), into (2), powerful (2), instead (2), will (2), looks (2), called (2), only (2), active (2), various (2), platforms (2), watch (2), space (2), notified (2), when (2), publish (2), content (2), play (2), around (2), yourself (2), check (2), repository (2), many (2), snippets (2), shown (2), permissive (2), reuse (2), projects (2), showcasing (2), important (2), features (2), demo (2), talks (2), libfx (2), record (2), args (2), turn (2), year (2), tools (2), techniques (2), switch (2), serialization (2), records (2), valhalla (2), panama (2), loom (2), leyden (2), amber (2), performance (2), patterns (2), pattern (2), matching (2), ramp (2), migration (2), meta (2), maven (2), lambda (2), javafx (2), basics (2), j_ms (2), dop (2), documentation (2), deprecation (2), libs (2), collections (2), architecture (2), tags (2), javascript (2), contact, imprint, introduction, improved, considerably, long, shot, from, proper, able, easily, usable, haven, high, add, belt, concept, quite, common, theme, languages, scala, lack, resort, constructions, always, reduces, readability, accessibility, situations, best, available, added, complexity, acceptable, capture, returned, lets, compiler, deduce, wanted, means, freely, across, expose, crazy, signatures, build, given, knowledge, rather, right, signature, ridiculous, goes, exposing, see, clearly, confused, imagine, needed, line, won, let, mean, handle, fact, depending, fail, run, construction, weak, spot, breaks, down, under, refactoring, extract, bad, neat, inference, enter, picture, combine, follows, else, unchecked, suppresswarnings, involve, specific, general, once, again, step, actual, every, interfaces, fine, extend, here, ampersand, correct, limits, then, parameters, expression, valid, express, creating, error, great, control, implementations, change, don, jdk, third, party, frameworks, know, anything, although, might, instances, couldn, pass, public, obvious, limit, desired, iterate, safety, resources, block, think, circle, likewise, circles, turns, times, say, been, writing, point, realize, isn, enough, maybe, mere, regular, often, simply, corporation, megacorp, collection, list, spoiler, end, weird, wants, our, goal, find, variant, background, why, show, returns, expects, should, whether, sure, heard, reserved, name, allows, specify, glance, opens, door, richer, turned, surprisingly, cool, things, today, keyword, toc, src, table, contents, source, lic, easier, later, tricks, thanks, 2018, slides, upcoming, past, schedule, recordings, virtual, threads, vector, structured, concurrency, lilliput, galahad, babylon, openjdk, conversation, book, club, videos, jms, newsletter, posts, testing, rant, jigsaw, jdeps, impulse, default, lang, review, comments, words, site, enabled, nipafx,


Text of the page (random words):
unlocking intersection types with var nipafx this site works well without javascript but it works even better with javascript enabled bluesky mastodon discord youtube twitch github stackoverflow rss words tags architecture clean code clean comments code review collections community core lang core libs default methods deprecation documentation dop generics impulse j_ms java 10 java 11 java 12 java 13 java 16 java 17 java 18 java 20 java 23 java 24 java 25 java 26 java 27 java 8 java 9 java basics java next javafx jdeps js junit 5 junit pioneer lambda libfx libraries maven meta migration on ramp optional pattern matching patterns performance project amber project jigsaw project leyden project loom project panama project valhalla rant record args records reflection serialization streams switch techniques testing tools turn of the year var blog posts newsletter the jms videos tags ai architecture book club clean code collections community conversation core libs deprecation documentation dop generics j_ms java 10 java 11 java 12 java 16 java 17 java 18 java 19 java 21 java 22 java 23 java 24 java 25 java 26 java 8 java 9 java basics java next javafx junit 5 junit pioneer lambda libraries maven meta migration on ramp openjdk optional pattern matching patterns performance project amber project babylon project galahad project leyden project lilliput project loom project panama project valhalla records reflection serialization streams structured concurrency switch techniques tools turn of the year var vector virtual threads recordings streams schedule code demos demos demos junit pioneer record args libfx talks my talks past upcoming slides about about me license privacy 2018 06 11 unlocking intersection types with var post generics java 10 var with var it is much easier to work with intersection types in java 10 and later you still need non trivial tricks with generics to declare intersection types but thanks to var it is now easy to create local variables of such types me me lic license unlocking intersection types with var source code want to play around with the code yourself check out the repository java x demo a project showcasing all important java 9 16 features it contains many of the snippets shown in this blog post it has a permissive license so you can reuse the code for your projects table of contents what are intersection types just create a new interface declaring intersection types with generics declaring variables of intersection types reflection share follow share this post with your community i m active on various platforms watch this space or follow me there to get notified when i publish new content src want to play around with the code yourself check out the repository java x demo a project showcasing all important java 9 16 features it contains many of the snippets shown in this blog post it has a permissive license so you can reuse the code for your projects toc what are intersection types just create a new interface declaring intersection types with generics declaring variables of intersection types reflection s f share this post with your community i m active on various platforms watch this space or follow me there to get notified when i publish new content whether you re already using java 10 or not i m sure you ve heard all about var java s new keyword reserved type name that allows you to declare local variables without having to specify their types while var looks simple at first glance it opens the door to a richer type system and can be turned into a surprisingly powerful tool with which you can do some really cool things today i want to look at how to use it to work with intersection types elements should implement both closeable and iterator string does not compile closeable iterator string elements try only works because elements is closeable try elements the method stream expects an iterator e and returns a stream e so it can only be called if elements implements it optional string first stream elements filter s s startswith findany the declaration of elements looks pretty weird it wants the variable to be of two types closeable and iterator string that s called an intersection type but java s syntax doesn t allow them and so the code doesn t even compile our goal is to find a variant that does after some background on the why what and how of intersection types in java i will show you how to use them with var spoiler the declaration will end up as var elements what are intersection types we ve all been in this situation you re writing a method and at some point realize that some parameter s type isn t powerful enough you need more maybe a list instead of a collection or a megacorp instead of a mere regular corporation often that s pretty straight forward there s a type which has what you need so you can simply use it other times it s not so easy though as an example say you need an iterator to also be closeable so you can do this static e optional e firstmatch closeable iterator e elements predicate super e condition try elements stream turns iterator e into stream e return stream elements filter condition findany you want to iterate over elements so it needs to be an iterator but you also want the safety of a try with resources block so it needs to be closeable as well if you think of the type iterator as a circle that contains all variables of that type and likewise for closeable elements needs to be in the intersection of these circles it needs to be of an intersection type of iterator and closeable just create a new interface the obvious way to limit elements to the desired types is to create a new interface public interface closeableiterator e extends closeable iterator e static e optional e firstmatch closeableiterator e elements predicate super e condition throws ioexception that s great if you have control over all implementations of closeable and iterator and can change them to also implement closeableiterator but what if you don t neither the jdk nor third party libraries and frameworks know anything about your new interface and although they might return instances that implement both closeable and iterator you still couldn t pass them to firstmatch scanner implements iterator string and closeable scanner scanner new scanner system in optional string dollarword compile error because scanner is no closeableiterator firstmatch iterator s s startswith no what you really need is a way to express closeable iterator e without creating a new interface declaring intersection types with generics while you can t declare a variable as closeable iterator e that expression can be syntactically valid in java just not as a type in a variable declaration but as a bounded type parameter for example in a generic method generics allow intersection types in bounded type parameters private static e t extends closeable iterator e optional e firstmatch t elements predicate super e condition throws ioexception that s not straight forward but it works first you declare a new type parameter t which has to extend closeable and iterator here the ampersand is syntactically correct and limits t to the intersection of these two types and then you declare elements as being of that type the next step is to get an actual instance of closeable iterator that s pretty easy every class that implements both interfaces for example scanner works fine scanner scanner new scanner system in optional string dollarword firstmatch scanner s s startswith but what if the instance is not so easy to create what if you need to involve another method and its return type can not be specific like scanner but needs to be the general intersection we can once again use generics for that suppresswarnings unchecked private static t extends closeable iterator string t createcloseableiterator boolean empty if empty return t new empty else return t new scanner system in you can combine createcloseableiterator and firstmatch as follows optional string dollarword firstmatch createcloseableiterator empty s s startswith that s actually pretty neat and all of that works without var so where does local variable type inference enter the picture that s next declaring variables of intersection types the construction we have so far has the weak spot that it breaks down under refactoring want to extract a variable for createcloseableiterator empty that s too bad because without var you can t does not compile closeable iterator string elements createcloseableiterator empty compiles but can not be passed to firstmatch closeable elements createcloseableiterator empty iterator string elements createcloseableiterator empty compiles and can be passed but can fail at run time depending on empty scanner elements scanner createcloseableiterator empty empty elements empty createcloseableiterator empty what you really need is the first line but java s syntax won t let you compile it that doesn t mean the jvm can t handle it though in fact this would work static t extends closeable iterator string void readandprint boolean empty throws ioexception t elements createcloseableiterator empty optional string dollarword firstmatch elements s s startswith system out println dollarword this goes too far though we re now exposing a type t to callers of this method that they see neither as parameter nor return type and would clearly be confused by and imagine what the method would look like if we needed another such variable no createcloseableiterator and firstmatch have a right to a complicated signature because they actually need it but readandprint is ridiculous is there no better way to declare elements after all this build up and given your knowledge of how var works the solution is rather straight forward static void readandprint boolean empty throws ioexception var elements createcloseableiterator empty optional string dollarword firstmatch elements s s startswith system out println dollarword there you go with var you can declare elements in a way that lets the compiler deduce that its type is the intersection of closeable and iterator just like you wanted that means you can now freely declare such variables and use them across methods without having to expose your callers to crazy generic signatures use var to capture a generic method s returned intersection type reflection while the concept of intersection types is quite simple and a common theme in other jvm languages like scala java s lack of first class support makes it complicated to work with you have to resort to non trivial constructions using generics and that always reduces the code s readability and accessibility still there are situations where they are the best available solution and their added complexity is acceptable with the introduction of var the situation improved considerably even if it s still a long shot from proper support being able to easily declare variables of an intersection type makes them much more usable if you haven t already it is high time to add intersection types to your tool belt bluesky mastodon discord youtube twitch github stackoverflow rss imprint privacy contact license
Images from subpage: "nipafx.dev/turn-of-the-year/" Verify
Images from subpage: "nipafx.dev/var/" Verify
Images from subpage: "nipafx.dev/posts/" Verify
Images from subpage: "nipafx.dev/news/" Verify
Images from subpage: "nipafx.dev/ai/" Verify

Verified site has: 94 subpage(s). Do you want to verify them? Verify pages:

1-5 6-10 11-15 16-20 21-25 26-30 31-35 36-40 41-45 46-50
51-55 56-60 61-65 66-70 71-75 76-80 81-85 86-90 91-94


The site also has references to the 1 subdomain(s)

  slides.nipafx.dev  Verify


Top 50 hastags from of all verified websites.

Supplementary Information (add-on for SEO geeks)*- See more on header.verify-www.com

Header

HTTP/2 301
server GitHub.com
content-type text/html
location htt????/nipafx.dev/java-var-intersection-types/
access-control-allow-origin *
expires Wed, 15 Jul 2026 12:02:39 GMT
cache-control max-age=600
x-proxy-cache MISS
x-github-request-id CD14:15C5E8:2162561:21D5B72:6A577487
accept-ranges bytes
age 0
date Wed, 15 Jul 2026 11:52:39 GMT
via 1.1 varnish
x-served-by cache-rtm-ehrd2290034-RTM
x-cache MISS
x-cache-hits 0
x-timer S1784116360.523711,VS0,VE113
vary Accept-Encoding
x-fastly-request-id d3a65f1ae1545a1e8daaaf13e832e3c7f5c1a2c8
content-length 162
HTTP/2 200
server GitHub.com
content-type text/html; charset=utf-8
last-modified Wed, 15 Jul 2026 01:37:45 GMT
access-control-allow-origin *
etag W/ 6a56e469-31056
expires Wed, 15 Jul 2026 12:02:39 GMT
cache-control max-age=600
content-encoding gzip
x-proxy-cache MISS
x-github-request-id 3E44:5994A:216BF8B:21DF537:6A577487
accept-ranges bytes
age 0
date Wed, 15 Jul 2026 11:52:39 GMT
via 1.1 varnish
x-served-by cache-rtm-ehrd2290034-RTM
x-cache MISS
x-cache-hits 0
x-timer S1784116360.649138,VS0,VE125
vary Accept-Encoding
x-fastly-request-id f60047aafa3024a6707a870ec7411422f8c8899a
content-length 46784

Meta Tags

title="Unlocking Intersection Types With var // nipafx"
charset="utf-8"
http-equiv="x-ua-compatible" content="ie=edge"
name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"
name="generator" content="Gatsby 5.7.0"
data-react-helmet="true" name="description" content="Java 10's var makes intersection types in Java more approachable. Generics tricks are still needed, but var makes it easy to declare such variables."
data-react-helmet="true" name="twitter:card" content="summary_large_image"
data-react-helmet="true" name="twitter:site" content="@nipafx"
data-react-helmet="true" name="twitter:creator" content="@nipafx"
data-react-helmet="true" name="twitter:title" content="Unlocking Intersection Types With var // nipafx"
data-react-helmet="true" name="twitter:description" content="Java 10's var makes intersection types in Java more approachable. Generics tricks are still needed, but var makes it easy to declare such variables."
data-react-helmet="true" name="twitter:image" content="htt????/nipafx.dev/static/a860e3712c0ee913e36db78259f32768/02dbd/var-intersection-type-venn.png"
data-react-helmet="true" name="keywords" content="intersection types"
data-react-helmet="true" property="og:title" content="Unlocking Intersection Types With var // nipafx"
data-react-helmet="true" property="og:type" content="article"
data-react-helmet="true" property="og:image" content="htt????/nipafx.dev/static/a860e3712c0ee913e36db78259f32768/02dbd/var-intersection-type-venn.png"
data-react-helmet="true" property="og:url" content="htt????/nipafx.dev/java-var-intersection-types/"
data-react-helmet="true" property="og:description" content="Java 10's var makes intersection types in Java more approachable. Generics tricks are still needed, but var makes it easy to declare such variables."
data-react-helmet="true" property="og:site_name" content="nipafx // You. Me. Java."
name="theme-color" content="#69ea7d"

Load Info

page size46784
load time (s)0.419998
redirect count1
speed download111656
server IP 185.199.109.153
* all occurrences of the string "http://" have been changed to "htt???/"