An interesting question was asked on reddit's /r/java recently: Should Iterators be used to modify a custom Collection? Paraphrasing the question: The author wondered whether a custom java.util.Iterator that is returned from a mutable Collection.iterator() method should implement the weird Iterator.remove() method. A totally understandable question. What does Iterator.remove() do? Few people ever use this … Continue reading Should I Implement the Arcane Iterator.remove() Method? Yes You (Probably) Should
Category: java 8
A Hidden jOOQ Gem: Foreach Loop Over ResultQuery
A recent question on Stack Overflow about jOOQ caught my attention. The question essentially asked: Why do both of these loops work? // With fetch() for (MyTableRecord rec : ctx .selectFrom(MY_TABLE) .orderBy(MY_TABLE.COLUMN) .fetch() // fetch() here ) { doThingsWithRecord(rec); } // Without fetch() for (MyTableRecord rec : ctx .selectFrom(MY_TABLE) .orderBy(MY_TABLE.COLUMN) // No fetch() here ) … Continue reading A Hidden jOOQ Gem: Foreach Loop Over ResultQuery
Using jOOλ to Combine Several Java 8 Collectors into One
With Java 8 being mainstream now, people start using Streams for everything, even in cases where that's a bit exaggerated (a.k.a. completely nuts, if you were expecting a hyperbole here). For instance, take mykong's article here, showing how to collect a Map's entry set stream into a list of keys and a list of values: … Continue reading Using jOOλ to Combine Several Java 8 Collectors into One
The Java JIT Compiler is Darn Good at Optimization
"Challenge accepted" said Tagir Valeev when I recently asked the readers of the jOOQ blog to show if the Java JIT (Just-In-Time compilation) can optimise away a for loop. Tagir is the author of StreamEx, very useful Java 8 Stream extension library that adds additional parallelism features on top of standard streams. He's a speaker … Continue reading The Java JIT Compiler is Darn Good at Optimization
How Functional Programming will (Finally) do Away With the GoF Patterns
A recent article about various ways to implement structural pattern matching in Java has triggered my interest: http://blog.higher-order.com/blog/2009/08/21/structural-pattern-matching-in-java The article mentions a Scala example where a tree data structure can be traversed very easily and neatly using Scala's match keyword, along with using algebraic data types (more specifically, a sum type): def depth(t: Tree): Int … Continue reading How Functional Programming will (Finally) do Away With the GoF Patterns
Cyclops-react Organises the Cambrian Explosion of Java 8 Libraries
We’re excited to announce another very interesting guest post on the jOOQ Blog by John Mcclean from AOL. AOL is a global digital media and technology company, founded in 1985 and once known as America Online, AOL is now part of the Verizon Group. AOL focuses on four areas - video, mobile, ad technology and … Continue reading Cyclops-react Organises the Cambrian Explosion of Java 8 Libraries
JSR-308 and the Checker Framework Add Even More Typesafety to jOOQ 3.9
Java 8 introduced JSR-308, which added new annotation capabilities to the Java language. Most importantly: Type annotations. It is now possible to design monsters like the below: https://twitter.com/lukaseder/status/711612663202238464 The code displayed in that tweet really compiles. Every type can be annotated now, in order to enhance the type system in any custom way. Why, you … Continue reading JSR-308 and the Checker Framework Add Even More Typesafety to jOOQ 3.9
The Parameterless Generic Method Antipattern
A very interesting question was posted to Stack Overflow and reddit just recently about Java generics. Consider the following method: <X extends CharSequence> X getCharSequence() { return (X) "hello"; } While the unsafe cast seems a bit wonky, and you might guess there's something wrong here, you can still go ahead and compile the following … Continue reading The Parameterless Generic Method Antipattern
jOOQ Tuesdays: Ming-Yee Iu Gives Insight into Language Integrated Querying
Welcome to the jOOQ Tuesdays series. In this series, we’ll publish an article on the third Tuesday every other month where we interview someone we find exciting in our industry from a jOOQ perspective. This includes people who work with SQL, Java, Open Source, and a variety of other related topics. We have the pleasure … Continue reading jOOQ Tuesdays: Ming-Yee Iu Gives Insight into Language Integrated Querying
Watch Out For Recursion in Java 8’s [Primitive]Stream.iterate()
An interesting question by Tagir Valeev on Stack Overflow has recently caught my attention. To keep things short (read the question for details), while the following code works: public static Stream<Long> longs() { return Stream.iterate(1L, i -> 1L + longs().skip(i - 1L) .findFirst() .get()); } longs().limit(5).forEach(System.out::println); printing 1 2 3 4 5 The following, similar … Continue reading Watch Out For Recursion in Java 8’s [Primitive]Stream.iterate()
