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
Tag: generics
An Ingenious Workaround to Emulate an Application of Union Types in Java
Before I move on with the actual article, I'd like to give credit to Daniel Dietrich, author of the awesome vavr library, who has had the idea before me: https://twitter.com/danieldietrich/status/699633269202149377 Contravariant Generic Bounds It all started with a tweet: https://twitter.com/lukaseder/status/699588908095508480 I wanted to do something like pattern-matching a common super type of a set of … Continue reading An Ingenious Workaround to Emulate an Application of Union Types in Java
This Common API Technique is Actually an Anti-Pattern
I admit, we've been lured into using this technique as well. It's just so convenient, as it allows for avoiding a seemingly unnecessary cast. It's the following technique here: interface SomeWrapper { <T> T get(); } Now you can type safely assign anything from the wrapper to any type: SomeWrapper wrapper = ... // Obviously … Continue reading This Common API Technique is Actually an Anti-Pattern
Don’t be Fooled by Generics and Backwards-Compatibility. Use Generic Generic Types
I've recently had a very interesting discussion with Sebastian Gruber from Ergon, a very early jOOQ customer, whom we're in close touch with. Talking to Sebastian has lead our engineering team to the conclusion that we should completely rewrite the jOOQ API. Right now, we already have lots of generics for various purposes, e.g. Generics … Continue reading Don’t be Fooled by Generics and Backwards-Compatibility. Use Generic Generic Types
Java 8 Friday: Optional Will Remain an Option in Java
At Data Geekery, we love Java. And as we're really into jOOQ's fluent API and query DSL, we're absolutely thrilled about what Java 8 will bring to our ecosystem. Java 8 Friday Every Friday, we're showing you a couple of nice new tutorial-style Java 8 features, which take advantage of lambda expressions, extension methods, and … Continue reading Java 8 Friday: Optional Will Remain an Option in Java
Top 10 Ceylon Language Features I Wish We Had In Java
What does one do when Hibernate is "finished" and feature complete and one needs new challenges? Right. One creates a new JVM language called Ceylon. On November 12, 2013, Ceylon 1.0.0 was finally released and we congratulate the whole team at Red Hat for their achievements in what looks like a very promising new JVM … Continue reading Top 10 Ceylon Language Features I Wish We Had In Java
A Lesser-Known Java 8 Feature: Generalized Target-Type Inference
Going through the list of Java 8 features, Generalized Target-Type Inference struck me as a particularly interesting, lesser-known gem. It looks as though the Java language designers will ease some of the pain that we've been having with generics in the past (Java 5-7). Let's have a look at their example: class List<E> { static … Continue reading A Lesser-Known Java 8 Feature: Generalized Target-Type Inference
The Dangers of Correlating Subtype Polymorphism with Generic Polymorphism
Java 5 has introduced generic polymorphism to the Java ecosystem. This has been a great addition to the Java language, even if we're all aware of the numerous caveats due to generic type erasure and the consequences thereof. Generic polymorphism (also known as parametric polymorphism) is usually maintained orthogonally to possibly pre-existing subtype polymorphism. A … Continue reading The Dangers of Correlating Subtype Polymorphism with Generic Polymorphism
Overload API methods with care – the sequel
I had recently blogged about funny issues that arise when overloading API methods with generics involved: https://blog.jooq.org/overload-api-methods-with-care/ I promised a sequel as I have encountered more trouble than that, so here it is. The trouble with generics and varargs Varargs are another great feature introduced in Java 5. While being merely syntactic sugar, you can … Continue reading Overload API methods with care – the sequel
Overload API methods with care
Overloading methods is a strong concept in API design, especially when your API is a fluent API or DSL (Domain Specific Language). This is the case for jOOQ, where you often want to use the exact same method name for various means of interaction with the library. Example: jOOQ Conditions package org.jooq; public interface Condition … Continue reading Overload API methods with care