What is a Sealed Class/Interface ?

What is a Sealed Class/Interface ?

Hello Folks,

Java version 17 has been released around 15 days ago in Sept, 2021. There are a number of features that have been added to the Java language, some have been removed as well though.

Today, we are going to talk about one such feature added to the language - "Sealed" classes or interfaces.

What exactly is the concept of Sealed?

Sealed classes and interfaces restrict which other classes or interfaces may extend or implement them.

This feature was actually added as a preview feature with JDK15. With JDK16, it was further refined but remained as a preview feature.

With JDK17, the feature has finally arrived without any change from JDK16.

Are you interested in knowing why do we need actually such classes/interfaces? Let's not try to learn everything in one go :) and discuss about it in next article. Till then, stay tuned !

PS: A preview feature is?a new feature whose design, specification, and implementation are complete, but which is not permanent, which means that the feature may exist in a different form or not at all in future JDK releases.

Thanks for reading this far!


要查看或添加评论,请登录

Shiv Dhiman的更多文章

  • Team Fridays | Decision-making activity around Conflicting views

    Team Fridays | Decision-making activity around Conflicting views

    This Friday's session with the team was around a decision-making activity around conflicting views on a problem…

  • Team Fridays | Learning & Sharing

    Team Fridays | Learning & Sharing

    Learning and sharing are key to the team's cohesiveness and growth. And, Fridays, I believe, are the best days to do so.

  • How to write a Sealed Interface ?

    How to write a Sealed Interface ?

    Finally, we've come to the last part of the Sealed concept. We've already learnt - what, why and how parts in last…

  • How to write a Sealed Class ?

    How to write a Sealed Class ?

    In the last two articles, we discussed the what and why parts - as what's a sealed class and second, why do we even…

  • Why do we need a Sealed Class?

    Why do we need a Sealed Class?

    Hello Folks, In the last article here, we discussed about what is exactly the concept of Sealed? Today, we are going to…

社区洞察

其他会员也浏览了