From the course: Java SE 11 Developer (1Z0-819) Cert Prep
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Possible and impossible casts - Java Tutorial
From the course: Java SE 11 Developer (1Z0-819) Cert Prep
Possible and impossible casts
- Let's investigate how the compiler addresses the question of whether a cast is actually possible or not before it allows you to write the code for it. First, we'll review the reference casting rules. A cast down a class hierarchy, and I'm being specific about class here, succeeds at compilation time. If the object isn't actually of the cast type, then the cast will fail at runtime, and it will throw a ClassCastException. Casts up the class hierarchy, again, specific to class hierarchy, are always valid and therefore redundant. The compiler permits them, though it's important to realize that your development environment, your IDE, might actually complain. That's not the same thing as the language not permitting it though. A cast across a class hierarchy is rejected at compile time. The point there is that the two classes do not share an "is-a" relationship in any way, and so that's just downright impossible. But what happens with interfaces? Generally speaking, if an assignment from…
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 3: Java object-oriented approach1m 21s
-
(Locked)
Learning objectives40s
-
(Locked)
Source files and basic type declarations6m 32s
-
(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 objectives47s
-
(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)
Question deep dive3m 34s
-
(Locked)
-
-
(Locked)
Module 5: Working with streams and lambda expressions39s
-
(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)
-
-
(Locked)
Module 9: Annotations, localization, and secure coding in Java SE application1m 4s
-
(Locked)
Learning objectives36s
-
(Locked)
Annotation declaration and elements7m 6s
-
(Locked)
Target, retention, and inspection8m 49s
-
(Locked)
Element types and repeatable annotations3m 6s
-
(Locked)
Question deep dive2m 50s
-
(Locked)