In this article, we will briefly discuss about self-referential generics with one example. Consider the below class definition: Here Bird is a self-referential generic type. T is a subclass of some parameterization of Bird. The expression T extends Bird<T> ensures that subtypes of Bird depends on themselves. For example, a bird type Goose extends Bird<Goose>: … [Read more...] about Solid Code Design – Part 7 – Self-Referential Generics In Java
Java Generics
Solid Code Design – Part 6 – Advanced Java Generics
In Part 4 and Part 5, I introduced you with the concept of invariance and covariance respectively. In this article, I will cover contravariance. We will use the same type hierarchies and code from the Part 5. For your convenience, I will provide the type hierarchies once again here. Contravariance To take advantage of covariance, we use lower bounded wildcards as … [Read more...] about Solid Code Design – Part 6 – Advanced Java Generics
Solid Code Design – Part 5 – Advanced Java Generics
In Part 4, I introduced you with the concept of invariance. In this article, I will cover covariance. I will use the below type hierarchies for our discussion. Get Started To start, I will introduce you with the code for the above type hierarchies as given below. I will also introduce with the below generic class. For our convenience, I will … [Read more...] about Solid Code Design – Part 5 – Advanced Java Generics
Solid Code Design – Part 4 – Advanced Java Generics
In this article, I will focus on the concept of invariance. I will cover covariance and contravariance in upcoming articles. Type Systems play a big role in programming languages. In computations, we deal with values. Every value has some type. Who assigns types to the values? The answer is the type system. Wrongly assigned types to values may crash the whole program at … [Read more...] about Solid Code Design – Part 4 – Advanced Java Generics