Generic Constructors: What are They Good For?

Generics can be declared on types (classes and interfaces), methods, and constructors. Wait, constructors? That one threw me a little. I’ve never actually seen or used this feature. It makes logical sense to be able to declare a generic type on a constructor; after all, it’s just a special case of a method.

I could explain how to declare and use generic constructors in a rigorous and academic way, but that doesn’t give us a sense of if or whether it’s actually a useful feature. Instead, let’s see how and how often they’re used in the real world. That’s why we have open source! Let’s look for examples of generic constructors in some of the most popular Java projects and see if we can find any patterns.

Continue Reading