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 Language
Pattern Matching for Switch in Java 21 – Part 2
In the Part 1, we discussed about improved enum constants as case labels in Java 21. In this article, we will focus on patterns in switch labels. In general, the value of the selector expression is compared with the case label by an equality test. But this mechanism changes when patterns come at the case label. In this case, label is selected based on the result of pattern … [Read more...] about Pattern Matching for Switch in Java 21 – Part 2
The Z Garbage Collector (ZGC) – Colored Pointers, Load Barriers, and Store Barriers
In the previous article, we have seen the fundamental difference between the non-generational ZGC and the generational ZGC. In this article, we will briefly cover the idea behind colored pointers, load barriers, and store barriers. ZGC (both non-generational and generational) reads and modifies the object graph in heap memory concurrently with the application … [Read more...] about The Z Garbage Collector (ZGC) – Colored Pointers, Load Barriers, and Store Barriers
Pattern Matching for Switch in Java 21 – Part 1
We will start this article with the below diagram. In both cases (switch statement and switch expression), we use the keyword switch and terms selector expression and switch block. But there are a few important differences. One difference is that switch expressions cannot have empty switch blocks, unlike switch statements. The below examples will … [Read more...] about Pattern Matching for Switch in Java 21 – Part 1
Record Patterns in Java 21
We will start this article with record classes. Record Classes Consider the below Java class: The above MaxMin class basically a data aggregate that carrying two data values: max and min. This class is serving as a data carrier. Instead of writing one public constructor with all the data fields, a public accessor method for each data field, equals method, hashCode … [Read more...] about Record Patterns in Java 21