instanceof Java Keyword Tutorial | What's new?

Описание к видео instanceof Java Keyword Tutorial | What's new?

Learn what's new with the Java 14 instanceof operator. Java 14 now supports Pattern Matching as a preview feature when using the instanceof operator... but Hold Up! A word of caution before blindly using this new features in your code.

The instanceof operator in Java 14 has been extended to allow for what's called a "test type pattern" which allows for Pattern Matching to be used. This test type pattern is a combination of a predicate that specifies a Type (like instanceof Type) and a binding variable (that's what is new here).

No more explicit casting and no more declaration of local variables, less boilerplate code .. great! Just be aware that there are some scoping rules with the new binding variable that are well described in the JEP 305 .

Although Java 14's new instanceof feature is great, we should remember that sometimes using instanceof can be considered a code smell or an anti-pattern. I will cover when to use and not use instanceof as well as offer some alternatives.

Check out the MVP Java blog post here:
http://mvpjava.com/instanceof-java-14

00:00 Introduction
01:58 Project Code walk through for instanceof demo | pre Java 14
05:06 New Java 14 instanceof preview feature explained
08:16 Alternatives to instanceof | Best OO practice
09:33 When to use instanceof | Use cases
10:10 When to not use instanceof | Polymorphism


Resources:
-------------------------------------------------------------
JEP 305: Pattern Matching for instanceof (Preview):
https://openjdk.java.net/jeps/305


Java Magazine: Pattern Matching for instanceof in Java 14
https://blogs.oracle.com/javamagazine...


Other MVP Java Videos and Posts on Java preview features:
----------------------------------------------------------------
Java Records | Boilerplate Exterminator:
Blog: http://mvpjava.com/java-records/
YouTube:    • What is a Java Record?  

JDK 12 Switch Expression – Preview Feature
Blog: http://mvpjava.com/jdk-12-switch/
YouTube:    • Java 12 Switch Expression - Preview F...  

Code available on GitHub here:
https://github.com/mvpjava/java14-ins...


======================================================

Subscribe to MVP Java ...
https://www.youtube.com/c/MVPJava?sub...

Follow me ...
Website : http://www.mvpjava.com
Facebook :   / mvpjava  
Twitter :   / mvpjava  
GitHub : https://github.com/mvpjava
DockerHub: https://hub.docker.com/?namespace=mvp...
My Company: http://www.triomni-it.com

Комментарии

Информация по комментариям в разработке