r/programming • u/whackri • Dec 11 '21
Teeing, a hidden gem in the Java API
https://blog.frankel.ch/teeing-java-api/12
u/Monsieur_Moneybags Dec 11 '21
Good to know this exists, though you need Java 12 or higher. I wish it were in Java 8, which is what I'm still forced to use at work.
11
Dec 12 '21
If you're not yet on Java 12 then you can backport it with ~100 lines of code. Just go into Collectors and copy-paste bits until it compiles. It's only 2 methods, 1 class and 2 static fields.
I've done exactly that for other collectors. On my Java 8 codebase I have a class which is called something like FutureJDKCollectors. If/when we migrate to a newer JDK, I'll deprecate those and replace them with the real thing.
1
Dec 12 '21
This is an interesting take, especially when it comes to using static imports, but does the license allows this?
13
u/hugogrant Dec 12 '21
Why is there so much jargon in the stream API?
It's also funny to see a unix reference in the jdk (tee is the unix command that does this for outputting on the shell).