Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,330 --> 00:00:00,920
Welcome back.
2
00:00:01,290 --> 00:00:07,410
And this year, we are going to look at the Alvis operator and not NUL assertion operator.
3
00:00:07,800 --> 00:00:15,330
And in order to do so, I first of all start by commenting our name here because we used it and we saw
4
00:00:15,330 --> 00:00:15,840
how it works.
5
00:00:15,840 --> 00:00:16,129
Right.
6
00:00:16,410 --> 00:00:24,590
But now what I want to do, I want to assign our nullable name to a non nullable variable.
7
00:00:24,750 --> 00:00:27,720
So this value here should be a non nullable.
8
00:00:27,750 --> 00:00:28,070
Right.
9
00:00:28,080 --> 00:00:33,860
But I have another variable here called nullable name and I need to assign it to this variable.
10
00:00:33,870 --> 00:00:36,800
So sometimes you have this situation and you can't get around it.
11
00:00:37,140 --> 00:00:41,070
So what you can do is you can use the.
12
00:00:42,680 --> 00:00:49,970
Elvis operator in order to either assigned a value that is within that nullable name variable, so let's
13
00:00:49,970 --> 00:00:57,490
say the variable has a name in there and otherwise it's just going to have this default value.
14
00:00:58,010 --> 00:01:06,290
So question mark Colon, in order to say, OK, if Nullable is empty, then please use my default value
15
00:01:06,290 --> 00:01:11,480
that I have here otherwise used to value that is in the nullable name.
16
00:01:11,780 --> 00:01:18,920
So now if we print that name, we will see that it should say in this case, Dennis, because the nullable
17
00:01:18,920 --> 00:01:20,280
name is in fact, not now.
18
00:01:20,930 --> 00:01:21,810
So there we are.
19
00:01:21,830 --> 00:01:22,640
Name is Dennis.
20
00:01:23,180 --> 00:01:28,250
But now let's say we make nullable name now and we run this again.
21
00:01:29,240 --> 00:01:36,290
Then we see name is guest, OK, so if the value is now, then it's going to take the default value.
22
00:01:36,320 --> 00:01:44,690
So this one, this question mark colon here that we're using is the Elvis operator.
23
00:01:46,410 --> 00:01:51,990
All right, the next thing that I want to use is to not know assertion operator, which is the double
24
00:01:51,990 --> 00:01:58,950
exclamation mark operator that converts and nullable type to a non null type and throws a no pointer
25
00:01:58,950 --> 00:02:05,130
exception if the nullable type holds a null value, this is risky and you should only use it if you
26
00:02:05,310 --> 00:02:09,470
are 100 percent certain that there will be a value in the variable.
27
00:02:10,320 --> 00:02:11,440
So let's use it here.
28
00:02:11,670 --> 00:02:18,270
I'm going to say nullable name double exclamation mark thought to lower case.
29
00:02:18,780 --> 00:02:20,070
OK, so there is this.
30
00:02:21,050 --> 00:02:27,920
Method called to lower case, and it's going to put everything to a lower case value, so instead of
31
00:02:27,920 --> 00:02:30,770
guests, it's going to be a guest, for example.
32
00:02:30,920 --> 00:02:31,370
All right.
33
00:02:32,840 --> 00:02:38,990
So this here in our case will create the null pointer exception because we are really forcing it.
34
00:02:39,440 --> 00:02:45,740
And it's our own mistake because we didn't make sure that nullable name is, in fact, not now.
35
00:02:45,800 --> 00:02:53,080
So if you can see here, I'm getting a kotlin now, pointer exception in line 17.
36
00:02:53,090 --> 00:02:54,380
So in this line here.
37
00:02:56,020 --> 00:02:57,280
And this has to do with.
38
00:02:58,430 --> 00:03:04,920
Nullable name be know, so you can see it is null at this line, so that's why we get this error.
39
00:03:04,970 --> 00:03:10,070
So now if it's not now, because it was a Saint Denis here and we never change it to know.
40
00:03:10,700 --> 00:03:16,040
So if it's not null, it's going to print Dennis and lowercase.
41
00:03:17,080 --> 00:03:18,670
And your name is Dennis.
42
00:03:20,220 --> 00:03:21,960
So now if we print that.
43
00:03:25,310 --> 00:03:33,560
My name and we get rid of this print statement that we have before now to just print Dennis with a lowercase.
44
00:03:34,500 --> 00:03:36,000
So there we are, Dennis.
45
00:03:38,440 --> 00:03:45,850
All right, so now you have seen how no pointer exception works and how you can force one, you also
46
00:03:45,850 --> 00:03:48,660
have seen how multiples work in Scotland.
47
00:03:48,880 --> 00:03:51,520
And there's one last thing that I want to show you.
48
00:03:51,530 --> 00:03:53,100
But it will not make sense.
49
00:03:53,110 --> 00:03:58,480
You know, it will make more sense once we get into objects and variables.
50
00:03:58,640 --> 00:04:08,070
But I just want to very quickly show you that you can use the safe call operator in a chain.
51
00:04:08,560 --> 00:04:12,610
So here we are using a chain safe call, so to speak.
52
00:04:12,760 --> 00:04:16,800
So let's say we have a class called user and we create an object of it.
53
00:04:16,870 --> 00:04:18,740
There is a wife.
54
00:04:18,760 --> 00:04:23,860
So the user can have a wife, which is also of a class or of a type.
55
00:04:24,100 --> 00:04:26,470
And then this wife has an H.
56
00:04:26,740 --> 00:04:34,690
So what we can do is we can use a chain safe call here, for example, checking if the user is empty
57
00:04:34,990 --> 00:04:38,560
and then also checking if the user's wife is empty.
58
00:04:38,570 --> 00:04:39,940
So if it's now or not.
59
00:04:40,240 --> 00:04:40,730
OK.
60
00:04:40,750 --> 00:04:43,600
So if that's the case, then assign a value of zero.
61
00:04:43,930 --> 00:04:49,600
So as I said, this only makes sense once you understand the concept of object oriented programming.
62
00:04:49,600 --> 00:04:54,360
But if you come from another programming language, that will make now sense already.
63
00:04:54,640 --> 00:05:00,880
But otherwise, I think it makes sense to go into object oriented programming, which we will do in
64
00:05:00,880 --> 00:05:01,860
the next video.
65
00:05:01,870 --> 00:05:06,130
So the next thing that we're going to look at is actually classes and objects.
66
00:05:06,370 --> 00:05:08,920
And this is a little much for now.
67
00:05:09,010 --> 00:05:17,230
But I just wanted to show you this in order to complete this section or this lecture for nullable and
68
00:05:17,230 --> 00:05:17,620
codling.
69
00:05:18,100 --> 00:05:18,590
All right.
70
00:05:18,820 --> 00:05:24,970
So I'd say let's go to the next video where we're going to check out object oriented programming and
71
00:05:24,970 --> 00:05:26,580
how to create our own classes.
6964
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.