From the course: Java SE 17 Developer (1Z0-829) Cert Prep
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Additional topics in pattern-matched instanceof - Java Tutorial
From the course: Java SE 17 Developer (1Z0-829) Cert Prep
Additional topics in pattern-matched instanceof
- Let's take a look at the scope of our pattern variables. It turns out pattern variables are initialized only when instanceof yields true. We knew that. But the scope of these variables is accurately tracked to where they will have definitely been initialized. We need to be a little cautious perhaps with complex boolean expressions. But let's take a look at some code and you'll see the kinds of things I'm describing. So here's our most simple example. We have an object initialized to a String and we do an instanceof test to see if that object in fact refers to a String. But we also have a pattern String s to initialize s to refer to this same object if it is in fact string. And you'll notice in the positive side of the if test, we have s in scope, but if we try to print s out in the else side, it's not in scope. Which of course we would expect. If on the other hand, I invert the overall logic of the test, now s is not in scope in the if side, but it is in scope in the else side…
Download courses and learn on the go
Watch courses on your mobile device without an internet connection. Download courses using your iOS or Android LinkedIn Learning app.
Contents
-
-
(Locked)
Module 1: Working with Java data types introduction43s
-
(Locked)
Learning objectives52s
-
(Locked)
Java operators, part 110m 6s
-
(Locked)
Java operators, part 210m 47s
-
(Locked)
Promotions12m 30s
-
(Locked)
Casting5m 25s
-
(Locked)
Wrapper classes6m 41s
-
(Locked)
Primitives, references, and aliasing12m 48s
-
(Locked)
Question deep dive6m 27s
-
(Locked)
-
-
(Locked)
Learning objectives23s
-
(Locked)
Date-time API foundations, part 19m 44s
-
(Locked)
Date-time API foundations, part 29m 58s
-
(Locked)
Manipulating date-time objects10m 6s
-
(Locked)
Time-zone considerations, part 17m 34s
-
(Locked)
Time-zone considerations, part 210m 15s
-
(Locked)
Time-zone considerations, part 38m 2s
-
(Locked)
Question deep dive2m 40s
-
(Locked)
-
-
(Locked)
Module 2: Controlling program flow and exception handling introduction44s
-
(Locked)
Learning objectives43s
-
(Locked)
Simple loops11m 16s
-
(Locked)
Control using break and continue7m 10s
-
(Locked)
Using if/else statements3m 22s
-
(Locked)
Using switch statements4m 41s
-
(Locked)
The arrow form of switch11m 31s
-
(Locked)
Expressions with switch16m 3s
-
(Locked)
Question deep dive6m 56s
-
(Locked)
-
-
(Locked)
Learning objectives35s
-
(Locked)
Flow control with try/catch/finally18m 32s
-
(Locked)
Flow control with try-with-resources4m
-
(Locked)
Multi-catch and rethrowing4m 57s
-
(Locked)
Implementing AutoCloseable, part 110m 9s
-
(Locked)
Implementing AutoCloseable, part 29m 55s
-
(Locked)
Question deep dive5m 58s
-
(Locked)
-
-
(Locked)
Module 3: Java object-oriented approach introduction1m 44s
-
(Locked)
Learning objectives40s
-
(Locked)
Source files and basic type declarations10m 29s
-
(Locked)
Nested type declarations8m 31s
-
(Locked)
Inner class declarations, part 17m 6s
-
(Locked)
Inner class declaration, part 215m 22s
-
(Locked)
Local and anonymous class declarations9m 45s
-
(Locked)
Reachability analysis12m 59s
-
(Locked)
Question deep dive4m 14s
-
(Locked)
-
-
(Locked)
Learning objectives49s
-
(Locked)
Instance and static fields, part 18m 52s
-
(Locked)
Instance and static fields, part 212m 9s
-
(Locked)
Instance and static methods, part 18m 57s
-
(Locked)
Instance and static methods, part 211m 9s
-
(Locked)
Variable length argument handling3m 10s
-
(Locked)
Overloaded and overridden methods, part 19m 24s
-
(Locked)
Overloaded and overridden methods, part 212m 29s
-
(Locked)
Defining records12m 2s
-
(Locked)
Features of records14m 26s
-
(Locked)
Question deep dive3m 34s
-
(Locked)
-
-
(Locked)
Learning objectives1m 3s
-
(Locked)
Object and reference type11m 41s
-
(Locked)
Pattern matching in instanceof9m 17s
-
(Locked)
Additional topics in pattern-matched instanceof10m 6s
-
(Locked)
Possible and impossible casts6m 9s
-
(Locked)
Virtual method invocation6m 1s
-
(Locked)
Covariant returns2m 27s
-
(Locked)
Question deep dive2m 54s
-
(Locked)
-
-
(Locked)
Module 5: Working with streams and lambda expressions introduction54s
-
(Locked)
Learning objectives45s
-
(Locked)
Lambda expression syntax variations12m 8s
-
(Locked)
Lambda expression contexts6m 5s
-
(Locked)
Core functional interfaces10m 35s
-
(Locked)
Method references12m 16s
-
(Locked)
Question deep dive4m 45s
-
(Locked)
-
-
(Locked)
Learning objectives58s
-
(Locked)
Collection and reduction, part 113m 8s
-
(Locked)
Collection and reduction, part 26m 42s
-
(Locked)
Grouping and partitioning with collectors6m 33s
-
(Locked)
Downstream operations with collectors9m 10s
-
(Locked)
Parallel stream operation7m 21s
-
(Locked)
Question deep dive3m 53s
-
(Locked)
-
-
(Locked)
Learning objectives54s
-
(Locked)
Race conditions, deadlock, and livelock12m 20s
-
(Locked)
Transactional integrity12m 32s
-
(Locked)
Visibility16m 49s
-
(Locked)
Concurrent queues and collections10m 23s
-
(Locked)
Synchronizers, locks, and atomic types, part 114m
-
(Locked)
Synchronizers, locks, and atomic types, part 215m 57s
-
(Locked)
Question deep dive1m 26s
-
(Locked)