Java 15 new features | Pattern matching for instanceof operator | Java Beam

preview_player
Показать описание
Pattern Matching for instanceof in Java 14/15 introduces a pattern variable with the instanceof operator. If the instanceof condition is true, the pattern variable binds to the variable being compared, avoiding the need for explicit casting to use its members.

As a Java developer, you often read or write code that compares a reference variable to a type by using the instanceof operator. If the result is true, the next obvious step is to explicitly cast it to the type you compared it with, to access its members. These steps have an obvious repetition here, like, compare-ifTrue-cast

#JavaBeam #PatternMatchingInstanceOfOperator #Java
Рекомендации по теме