Welcome back.
And this video, we are going to look at the Elvis operator and not null assertion operator and in order
to do so, I.
First of all, start by commenting odd name here because we just did and we saw how it works, right?
But now what I want to do, I want to assign our Nullarbor name to a nonviable variable.
So this value here should be a null Nullarbor, right?
But I have another notable variable here called multiple name, and I need to assign it to this variable.
So sometimes you have this situation and you can't get around it.
So what you can do is you can use the.
Elvis operator in order to either assigned a value that is within that Nullarbor name variable, so
let's say the verbal has a name in there.
And otherwise, it's just going to have this default value.
So you use question mark colon in order to say, OK, if Nullarbor is empty, then please use my default
value that I have here otherwise used to value that is in the Nullarbor name.
So now if you print that name, we will see that it should say in this case, Dennis, because the Nullarbor
name is in fact not now.
So there we are.
Name is Dennis.
But now let's say we make Nullarbor name, though, and we run this again.
Then we see name as guest.
OK, so if the value is now, then it's going to take the default value.
So this one, this question mark colon here that we're using is the Elvis operator.
All right, the next thing that I want to use is to not know Assertion Operator, which is the double
exclamation mark operator that converts and gullible type to a non null type and throws a null pointer
exception if the noble type holds a null value.
This is risky, and you should only use it if you are 100 percent certain that there will be a value
in the variable.
So let's use it here.
I'm going to say noble name double exclamation mark thought to lower case.
OK, so there is this.
Method call to lowercase and it's going to put everything to a lowercase value.
So instead of guests, it's going to say guest, for example.
All right.
So this here in our case will create the null pointer exception because we are really forcing it.
And it's our own mistake because we didn't make sure that knowable name is in fact, not now.
So if you can see here, I'm getting a call in my pointer exception in line 17.
So in this line here.
And this has to do with.
Multiple name B no.
So you can see it is now at this line, so that's why we get this error.
So now if it's not now because it was the Santa Anas here and we never change it to, no.
So if it's not now it's going to print Dennis and lowercase.
And there we are.
Name is Dennis.
So now if we print that.
Notable name, and we get rid of this print statement that we have before now to just print Dennis with
a lowercase.
So there we are.
Dennis.
All right.
So now you have seen how no pointer exception works and how you can force one.
You also have seen how multiples work in Kotlin.
And there's one last thing that I want to show you, but it will not make sense.
You know, it will make more sense once we get into objects and variables.
But I just want to very quickly show you that you can use the safe call operator in a chain.
So here we are using a chain safe call, so to speak.
So let's say we have a class called user and we create an object of it.
There is a way for so the user can have a wife, which is also of a class or of a type.
And then this wife has an h.
So what we can do is we can use a chain safe call here, for example, checking if the user is empty.
And then also checking if the user's wife is empty.
So if it's null or not.
Okay, so if that's the case, then assign a value of zero.
So as I said, this only makes sense once you understand the concept of object oriented programming.
But if you come from another programming language, that will make now sense already.
But otherwise, I think it makes sense to go into object oriented programming, which we will do in
the next video.
So the next thing that we're going to look at is actually classes and objects.
And this is a little much for now, but I just wanted to show you this in order to complete this section
or this lecture for multiples in Portland.
All right.
So I'd say, let's go to the next video where we're going to check out object oriented programming and
how to create our own classes.