SlideShare a Scribd company logo
What happened since Java 11
Ron Veen
Agenda
● Java 8 to Java 11
● Java 12 to Java 17
Java 8
● Lambas
● Streams
Java 9
● JVM Modularization
● Http client
● Process API
● Private methods in interfaces
Java 10
● Local variable type inference
Java 11
● Type inference for lambda variables
● Flight recorder
● ZGC Garbage Collector
Java 12 - 17
● Switch expression
● Text blocks
● Records
● Instanceof
● Sealed classes
● Pattern matching for switch
Java 12 - 17 matrix
Switch
expression
Java 12 Preview
Java 13 2nd Preview
Java 14 Final
Java 15
Java 16
Java 17
Switch expression
● Label -> syntax
● No fall-through, eliminates the need for a break
● The value after the -> is value of the expression
● You can have multiple labels left of the ->
● Must be exhaustive
● Switch Labelled Rule
Switch expression
Switch expression
● Label : syntax
● Eliminates the need for a break
● Values are returned via yield
● You can have multiple labels on the left of the colon (:)
● Must be exhaustive
● break and continue are not allowed
● Switch Labelled Statement group
Switch expression
Switch expression
Java 12 - 17 matrix
Switch
expression
Text
blocks
Java 12 Preview
Java 13 2nd Preview Preview
Java 14 Final 2nd Preview
Java 15 Final
Java 16
Java 17
Text blocks
● Java String spanning multiple lines
● "Hello Java 17".equals("""
Hello Java 17""");
● Text block begins with """ + line terminator
● You can have " within a text block. No more escaping "
● Placement of final """ is import
○ On the same line: no line terminator
○ On its own line: line terminator (n) gets added
Text blocks
Text blocks
Text blocks
Text blocks
Java 12 - 17 matrix
Switch
expression
Text
blocks Records
Java 12 Preview
Java 13 2nd Preview Preview
Java 14 Final 2nd Preview Preview
Java 15 Final 2nd Preview
Java 16 Final
Java 17
Records
● Special kind of a class
● Specified in the header its content
● Generates its constructor, accessors, equals, hashCode and
toString methods
● Records are final
●
Records
● Compact constructor
Records
Records
● Cannot declare additional instance variables
● Cannot extend other classes or records
● Accessors not prefix with name => name() instead of getName()
● Extend interfaces
● Static fields, initializers and methods are allowed
● Add your own instance methods
● Nested classes and nested records are allowed
Records
Records
Records
● Data transfer objects
● Safer serialisation
Records
● boolean Class.isRecord ()
● RecordComponent[] Class.getRecordComponents()
Java 12 - 17 matrix
Switch
expression
Text
blocks Records instanceof
Java 12 Preview
Java 13 2nd Preview Preview
Java 14 Final 2nd Preview Preview Preview
Java 15 Final 2nd Preview 2nd Preview
Java 16 Final Final
Java 17
Instanceof pattern matching
● Pattern matching is a two stage process
● 1 testing (the object structure)
● 2 extracting data from the object
● Pattern
○ Predicate (test)
○ Set of local variables (pattern variables)
● Variables are only extracted if the test is successful
Instanceof pattern matching
Instanceof pattern matching
Instanceof pattern matching
Instanceof pattern matching
Java 12 - 17 matrix
Switch
expression
Text
blocks Records instanceof
Sealed
classes
Java 12 Preview
Java 13 2nd Preview Preview
Java 14 Final 2nd Preview Preview Preview
Java 15 Final 2nd Preview 2nd Preview Preview
Java 16 Final Final 2nd Preview
Java 17 Final
Sealed classes
Sealed classes
Sealed classes
● Subclasses need to be accessible to the sealed class during
compile time
● Subclasses need to directly extend the sealed class
● Subclasses must have one modifier of
○ final
○ sealed
○ non-sealed
● Subclasses need to be in the same module (or package) as the
sealed class
● Records are allowed in the permits clause
Sealed classes
● Sealed classes can be abstract
● boolean Class.isSealed( )
● Class<?> Class.permittedSubclasses ( )
● Link with pattern matching for exhaustive analysis of patterns
Java 12 - 17 matrix
Switch
expression
Text
blocks Records instanceof
Sealed
classes
Pattern
matching
Java 12 Preview
Java 13 2nd Preview Preview
Java 14 Final 2nd Preview Preview Preview
Java 15 Final 2nd Preview 2nd Preview Preview
Java 16 Final Final 2nd Preview
Java 17 Final Preview
● Support for patterns in case labels
● Two additional patterns
● Guarded pattern
● Parenthesized pattern
● Special support for null values
● Switch pattern matching and sealed classes
Pattern matching for switch
Pattern matching for switch
Pattern matching for switch
Pattern matching for switch
Pattern matching for switch
Pattern matching for switch
47
github.com/RonVeen/Java17Presentation
48
THANK YOU!

More Related Content

Similar to What happened since java 11

Annotations
AnnotationsAnnotations
Annotations
Knoldus Inc.
 
Java17_language_features.pdf
Java17_language_features.pdfJava17_language_features.pdf
Java17_language_features.pdf
RonVeen1
 
8 introduction to_java_script
8 introduction to_java_script8 introduction to_java_script
8 introduction to_java_script
Vijay Kalyan
 
Java 9/10/11 - What's new and why you should upgrade
Java 9/10/11 - What's new and why you should upgradeJava 9/10/11 - What's new and why you should upgrade
Java 9/10/11 - What's new and why you should upgrade
Simone Bordet
 
Java 8 best practices - Stephen Colebourne
Java 8 best practices - Stephen ColebourneJava 8 best practices - Stephen Colebourne
Java 8 best practices - Stephen Colebourne
JAXLondon_Conference
 
Learn To Code: Introduction to java
Learn To Code: Introduction to javaLearn To Code: Introduction to java
Learn To Code: Introduction to java
SadhanaParameswaran
 
javase8bestpractices-151015135520-lva1-app6892
javase8bestpractices-151015135520-lva1-app6892javase8bestpractices-151015135520-lva1-app6892
javase8bestpractices-151015135520-lva1-app6892
SRINIVAS C
 
Java SE 8 best practices
Java SE 8 best practicesJava SE 8 best practices
Java SE 8 best practices
Stephen Colebourne
 
Deggan Android Codestyle v1.0
Deggan Android Codestyle v1.0Deggan Android Codestyle v1.0
Deggan Android Codestyle v1.0
Fenton Martin
 
Java features. Java 8, 9, 10, 11
Java features. Java 8, 9, 10, 11Java features. Java 8, 9, 10, 11
Java features. Java 8, 9, 10, 11
Ivelin Yanev
 
Amber and beyond: Java language changes
Amber and beyond: Java language changesAmber and beyond: Java language changes
Amber and beyond: Java language changes
Stephen Colebourne
 
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
Chuk-Munn Lee
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and Xitrum
Ngoc Dao
 
Managing Binary Compatibility in Scala (Scala Lift Off 2011)
Managing Binary Compatibility in Scala (Scala Lift Off 2011)Managing Binary Compatibility in Scala (Scala Lift Off 2011)
Managing Binary Compatibility in Scala (Scala Lift Off 2011)
mircodotta
 
Java9to19Final.pptx
Java9to19Final.pptxJava9to19Final.pptx
Java9to19Final.pptx
iFour Technolab Pvt. Ltd.
 
Groovy / comparison with java
Groovy / comparison with javaGroovy / comparison with java
Groovy / comparison with java
Liviu Tudor
 
Java 9-10 What's New
Java 9-10 What's NewJava 9-10 What's New
Java 9-10 What's New
Nicola Pedot
 
Java concurrency
Java concurrencyJava concurrency
Java concurrency
Srinivasan Raghvan
 
Core Java Programming Language (JSE) : Chapter X - I/O Fundamentals
Core Java Programming Language (JSE) : Chapter X - I/O Fundamentals Core Java Programming Language (JSE) : Chapter X - I/O Fundamentals
Core Java Programming Language (JSE) : Chapter X - I/O Fundamentals
WebStackAcademy
 
Java training in Noida
Java training in NoidaJava training in Noida
Java training in Noida
Tech Mentro
 

Similar to What happened since java 11 (20)

Annotations
AnnotationsAnnotations
Annotations
 
Java17_language_features.pdf
Java17_language_features.pdfJava17_language_features.pdf
Java17_language_features.pdf
 
8 introduction to_java_script
8 introduction to_java_script8 introduction to_java_script
8 introduction to_java_script
 
Java 9/10/11 - What's new and why you should upgrade
Java 9/10/11 - What's new and why you should upgradeJava 9/10/11 - What's new and why you should upgrade
Java 9/10/11 - What's new and why you should upgrade
 
Java 8 best practices - Stephen Colebourne
Java 8 best practices - Stephen ColebourneJava 8 best practices - Stephen Colebourne
Java 8 best practices - Stephen Colebourne
 
Learn To Code: Introduction to java
Learn To Code: Introduction to javaLearn To Code: Introduction to java
Learn To Code: Introduction to java
 
javase8bestpractices-151015135520-lva1-app6892
javase8bestpractices-151015135520-lva1-app6892javase8bestpractices-151015135520-lva1-app6892
javase8bestpractices-151015135520-lva1-app6892
 
Java SE 8 best practices
Java SE 8 best practicesJava SE 8 best practices
Java SE 8 best practices
 
Deggan Android Codestyle v1.0
Deggan Android Codestyle v1.0Deggan Android Codestyle v1.0
Deggan Android Codestyle v1.0
 
Java features. Java 8, 9, 10, 11
Java features. Java 8, 9, 10, 11Java features. Java 8, 9, 10, 11
Java features. Java 8, 9, 10, 11
 
Amber and beyond: Java language changes
Amber and beyond: Java language changesAmber and beyond: Java language changes
Amber and beyond: Java language changes
 
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and Xitrum
 
Managing Binary Compatibility in Scala (Scala Lift Off 2011)
Managing Binary Compatibility in Scala (Scala Lift Off 2011)Managing Binary Compatibility in Scala (Scala Lift Off 2011)
Managing Binary Compatibility in Scala (Scala Lift Off 2011)
 
Java9to19Final.pptx
Java9to19Final.pptxJava9to19Final.pptx
Java9to19Final.pptx
 
Groovy / comparison with java
Groovy / comparison with javaGroovy / comparison with java
Groovy / comparison with java
 
Java 9-10 What's New
Java 9-10 What's NewJava 9-10 What's New
Java 9-10 What's New
 
Java concurrency
Java concurrencyJava concurrency
Java concurrency
 
Core Java Programming Language (JSE) : Chapter X - I/O Fundamentals
Core Java Programming Language (JSE) : Chapter X - I/O Fundamentals Core Java Programming Language (JSE) : Chapter X - I/O Fundamentals
Core Java Programming Language (JSE) : Chapter X - I/O Fundamentals
 
Java training in Noida
Java training in NoidaJava training in Noida
Java training in Noida
 

Recently uploaded

Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
Safe Software
 
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Pitangent Analytics & Technology Solutions Pvt. Ltd
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
operationspcvita
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Neo4j
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
Ivo Velitchkov
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
Edge AI and Vision Alliance
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
Antonios Katsarakis
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
Fwdays
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
Javier Junquera
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
Neo4j
 

Recently uploaded (20)

Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
 
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
 

What happened since java 11

  • 1. What happened since Java 11 Ron Veen
  • 2. Agenda ● Java 8 to Java 11 ● Java 12 to Java 17
  • 4. Java 9 ● JVM Modularization ● Http client ● Process API ● Private methods in interfaces
  • 5. Java 10 ● Local variable type inference
  • 6. Java 11 ● Type inference for lambda variables ● Flight recorder ● ZGC Garbage Collector
  • 7. Java 12 - 17 ● Switch expression ● Text blocks ● Records ● Instanceof ● Sealed classes ● Pattern matching for switch
  • 8. Java 12 - 17 matrix Switch expression Java 12 Preview Java 13 2nd Preview Java 14 Final Java 15 Java 16 Java 17
  • 9. Switch expression ● Label -> syntax ● No fall-through, eliminates the need for a break ● The value after the -> is value of the expression ● You can have multiple labels left of the -> ● Must be exhaustive ● Switch Labelled Rule
  • 11. Switch expression ● Label : syntax ● Eliminates the need for a break ● Values are returned via yield ● You can have multiple labels on the left of the colon (:) ● Must be exhaustive ● break and continue are not allowed ● Switch Labelled Statement group
  • 14. Java 12 - 17 matrix Switch expression Text blocks Java 12 Preview Java 13 2nd Preview Preview Java 14 Final 2nd Preview Java 15 Final Java 16 Java 17
  • 15. Text blocks ● Java String spanning multiple lines ● "Hello Java 17".equals(""" Hello Java 17"""); ● Text block begins with """ + line terminator ● You can have " within a text block. No more escaping " ● Placement of final """ is import ○ On the same line: no line terminator ○ On its own line: line terminator (n) gets added
  • 20. Java 12 - 17 matrix Switch expression Text blocks Records Java 12 Preview Java 13 2nd Preview Preview Java 14 Final 2nd Preview Preview Java 15 Final 2nd Preview Java 16 Final Java 17
  • 21. Records ● Special kind of a class ● Specified in the header its content ● Generates its constructor, accessors, equals, hashCode and toString methods ● Records are final ●
  • 24. Records ● Cannot declare additional instance variables ● Cannot extend other classes or records ● Accessors not prefix with name => name() instead of getName() ● Extend interfaces ● Static fields, initializers and methods are allowed ● Add your own instance methods ● Nested classes and nested records are allowed
  • 27. Records ● Data transfer objects ● Safer serialisation
  • 28. Records ● boolean Class.isRecord () ● RecordComponent[] Class.getRecordComponents()
  • 29. Java 12 - 17 matrix Switch expression Text blocks Records instanceof Java 12 Preview Java 13 2nd Preview Preview Java 14 Final 2nd Preview Preview Preview Java 15 Final 2nd Preview 2nd Preview Java 16 Final Final Java 17
  • 30. Instanceof pattern matching ● Pattern matching is a two stage process ● 1 testing (the object structure) ● 2 extracting data from the object ● Pattern ○ Predicate (test) ○ Set of local variables (pattern variables) ● Variables are only extracted if the test is successful
  • 35. Java 12 - 17 matrix Switch expression Text blocks Records instanceof Sealed classes Java 12 Preview Java 13 2nd Preview Preview Java 14 Final 2nd Preview Preview Preview Java 15 Final 2nd Preview 2nd Preview Preview Java 16 Final Final 2nd Preview Java 17 Final
  • 38. Sealed classes ● Subclasses need to be accessible to the sealed class during compile time ● Subclasses need to directly extend the sealed class ● Subclasses must have one modifier of ○ final ○ sealed ○ non-sealed ● Subclasses need to be in the same module (or package) as the sealed class ● Records are allowed in the permits clause
  • 39. Sealed classes ● Sealed classes can be abstract ● boolean Class.isSealed( ) ● Class<?> Class.permittedSubclasses ( ) ● Link with pattern matching for exhaustive analysis of patterns
  • 40. Java 12 - 17 matrix Switch expression Text blocks Records instanceof Sealed classes Pattern matching Java 12 Preview Java 13 2nd Preview Preview Java 14 Final 2nd Preview Preview Preview Java 15 Final 2nd Preview 2nd Preview Preview Java 16 Final Final 2nd Preview Java 17 Final Preview
  • 41. ● Support for patterns in case labels ● Two additional patterns ● Guarded pattern ● Parenthesized pattern ● Special support for null values ● Switch pattern matching and sealed classes Pattern matching for switch