From the course: Writing Secure Code for Android by Infosec
Unlock this course with a free trial
Join today to access over 24,900 courses taught by industry experts.
Null safety, part 5: Safe cast and unsafe cast operators
From the course: Writing Secure Code for Android by Infosec
Null safety, part 5: Safe cast and unsafe cast operators
- Null safety, part five. Safe cast, unsafe cast operators. Further down the road of null safety. Are we there yet? (chuckles) There's a lot to null safety, right? And I know it can be confusing at first. Let's talk now about the safe cast and the unsafe cast operators. You could safely cast using as? For example, I have something x, its String, possibly nullable, equals y, and then safely cast it to string. If we don't do the, as we might blow up, it might be incompatible. Now, let's see this example here. This safe cast operator, it will return a null instead of blowing up on us, instead of us getting a ClassCastException. If we cannot cast, if it's not possible, it'll just give us a null. So it's a way of safely trying to cast, even though we can't really do it. Even though the right-hand side of as? is a non-null type of string, the result of the cast is still nullable. Let's take a look at this example here. We've got an object of type Any, and we're assigning it 123. That's an…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
(Locked)
Understanding input risks14m 59s
-
(Locked)
Autocompletion, part 113m 34s
-
(Locked)
Autocompletion, part 29m 13s
-
(Locked)
Activity: Securing autocomplete4m 30s
-
(Locked)
Special characters, part 111m 4s
-
(Locked)
Special characters, part 26m 3s
-
(Locked)
Activity: Using special characters11m 25s
-
(Locked)
Null safety, part 112m 17s
-
(Locked)
Null safety, part 2: Safe call operator4m 41s
-
(Locked)
Null safety, part 3: Not-null operator3m 35s
-
(Locked)
Null safety, part 4: Elvis operator7m
-
(Locked)
Null safety, part 5: Safe cast and unsafe cast operators7m 57s
-
(Locked)
Null safety, part 6: Smart cast8m 55s
-
(Locked)
Activity: Implementing null safety, part 111m 35s
-
(Locked)
Activity: Implementing null safety, part 213m 18s
-
(Locked)
Activity: Implementing null safety, part 315m 15s
-
(Locked)
String interpolation11m 2s
-
(Locked)
Activity: Understanding string interpolation15m 8s
-
(Locked)
Format string attacks7m 42s
-
(Locked)
Regular expressions, part 114m 4s
-
(Locked)
Regular expressions, part 26m 26s
-
(Locked)
Activity: Working with regular expressions in Kotlin, part 114m 1s
-
(Locked)
Activity: Working with regular expressions in Kotlin, part 210m 3s
-
(Locked)
Activity: Validating input with regular expressions in Kotlin, part 314m 56s
-
(Locked)
Input sanitization7m 4s
-
(Locked)
Activity: Sanitizing input3m 51s
-
(Locked)
Activity: Clamping input to a range5m 16s
-
(Locked)
Kotlin filter and trim6m 35s
-
(Locked)
Activity: Filtering and trimming9m 49s
-
(Locked)
Cross-site attacks14m 13s
-
(Locked)
Activity: Exploring cross-site scripting10m 8s
-
(Locked)
Cross-app scripting4m 42s
-
(Locked)
Activity: Defending against cross-app scripting9m
-
(Locked)
Code tampering and injection, part 17m 7s
-
(Locked)
Code tampering and injection, part 210m 35s
-
(Locked)
Code tampering and injection, part 311m 37s
-
(Locked)
Activity: Filtering a malicious QR code, part 18m 57s
-
(Locked)
Activity: Filtering a malicious QR code, part 23m 59s
-
(Locked)
SQL injection14m 24s
-
(Locked)
SQL stored procedures4m 55s
-
(Locked)
Object deserialization, part 14m 48s
-
(Locked)
Object deserialization, part 24m 25s
-
(Locked)
Activity: Protecting JSON with an API key, part 116m 17s
-
(Locked)
Activity: Protecting JSON with an API key, part 24m 48s
-
(Locked)
Form validation, part 112m 12s
-
(Locked)
Form validation, part 29m 37s
-
(Locked)
Form validation, part 36m 29s
-
(Locked)
Activity: Validating form input, part 113m 29s
-
(Locked)
Activity: Validating form input, part 24m 36s
-
(Locked)
WebView vulnerabilities, part 111m 34s
-
(Locked)
WebView vulnerabilities, part 210m 13s
-
(Locked)
Activity: Securing Android WebView11m 53s
-
(Locked)
-
-
-
-
-
-