According to some surveys such as that of JetBrains, version 8 of Java is currently the most used by developers all over the world, despite being a 2014 release. What you are reading is one in a series of articles titled “Going beyond Java 8”, inspired by the contents of my book “Java for Aliens”. These articles will guide the reader step by step to explore the most important features introduced starting from version 9. The aim is to make the reader aware of how important it is to move forward from Java 8, explaining the enormous advantages that the latest versions of the language offer.
In this article, we will talk about an important novelty introduced in version 15 as a preview feature (see related article), and definitively made official as a standard feature with Java 17. This feature is known with the name of defined as Sealed Classes, but which actually also concerns interfaces, and therefore we prefer to call Sealed Types. Now we can declare classes and interfaces by imposing some limits on their extension/implementation. Before the advent of this feature, we could only prevent a class from being extended by declaring it final
(or by declaring all its constructors as private), but now we can decide which classes it can be extended by. This allows for greater control over inheritance, opening the way to other important features such as pattern matching for the switch
construct, which we will mention at the end of this article and which we will explore soon in a dedicated article.
from DZone.com Feed https://ift.tt/3cmL3nf
No comments:
Post a Comment