1 00:00:00,180 --> 00:00:00,900 Welcome back. 2 00:00:01,290 --> 00:00:08,670 And this video, we are going to look at the Elvis operator and not null assertion operator and in order 3 00:00:08,670 --> 00:00:09,990 to do so, I. 4 00:00:10,020 --> 00:00:16,100 First of all, start by commenting odd name here because we just did and we saw how it works, right? 5 00:00:16,440 --> 00:00:24,570 But now what I want to do, I want to assign our Nullarbor name to a nonviable variable. 6 00:00:24,780 --> 00:00:28,070 So this value here should be a null Nullarbor, right? 7 00:00:28,080 --> 00:00:33,750 But I have another notable variable here called multiple name, and I need to assign it to this variable. 8 00:00:33,870 --> 00:00:36,750 So sometimes you have this situation and you can't get around it. 9 00:00:37,140 --> 00:00:41,010 So what you can do is you can use the. 10 00:00:42,710 --> 00:00:49,760 Elvis operator in order to either assigned a value that is within that Nullarbor name variable, so 11 00:00:49,760 --> 00:00:52,580 let's say the verbal has a name in there. 12 00:00:53,450 --> 00:00:57,440 And otherwise, it's just going to have this default value. 13 00:00:58,040 --> 00:01:05,930 So you use question mark colon in order to say, OK, if Nullarbor is empty, then please use my default 14 00:01:05,930 --> 00:01:11,450 value that I have here otherwise used to value that is in the Nullarbor name. 15 00:01:11,810 --> 00:01:18,890 So now if you print that name, we will see that it should say in this case, Dennis, because the Nullarbor 16 00:01:18,890 --> 00:01:20,270 name is in fact not now. 17 00:01:20,960 --> 00:01:21,800 So there we are. 18 00:01:21,830 --> 00:01:22,580 Name is Dennis. 19 00:01:23,210 --> 00:01:28,220 But now let's say we make Nullarbor name, though, and we run this again. 20 00:01:29,270 --> 00:01:30,740 Then we see name as guest. 21 00:01:31,460 --> 00:01:36,290 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,440 --> 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,920 exclamation mark operator that converts and gullible type to a non null type and throws a null pointer 25 00:01:58,920 --> 00:02:02,070 exception if the noble type holds a null value. 26 00:02:02,370 --> 00:02:08,699 This is risky, and you should only use it if you are 100 percent certain that there will be a value 27 00:02:08,699 --> 00:02:09,479 in the variable. 28 00:02:10,350 --> 00:02:11,430 So let's use it here. 29 00:02:11,730 --> 00:02:18,220 I'm going to say noble name double exclamation mark thought to lower case. 30 00:02:18,810 --> 00:02:20,040 OK, so there is this. 31 00:02:21,050 --> 00:02:26,390 Method call to lowercase and it's going to put everything to a lowercase value. 32 00:02:27,020 --> 00:02:30,770 So instead of guests, it's going to say guest, for example. 33 00:02:30,980 --> 00:02:31,340 All right. 34 00:02:32,870 --> 00:02:38,930 So this here in our case will create the null pointer exception because we are really forcing it. 35 00:02:39,470 --> 00:02:45,710 And it's our own mistake because we didn't make sure that knowable name is in fact, not now. 36 00:02:45,800 --> 00:02:53,050 So if you can see here, I'm getting a call in my pointer exception in line 17. 37 00:02:53,090 --> 00:02:54,350 So in this line here. 38 00:02:56,080 --> 00:02:57,220 And this has to do with. 39 00:02:58,430 --> 00:02:59,780 Multiple name B no. 40 00:03:00,560 --> 00:03:04,880 So you can see it is now at this line, so that's why we get this error. 41 00:03:04,970 --> 00:03:10,040 So now if it's not now because it was the Santa Anas here and we never change it to, no. 42 00:03:10,730 --> 00:03:16,010 So if it's not now it's going to print Dennis and lowercase. 43 00:03:17,080 --> 00:03:17,840 And there we are. 44 00:03:17,860 --> 00:03:18,610 Name is Dennis. 45 00:03:20,220 --> 00:03:21,900 So now if we print that. 46 00:03:25,310 --> 00:03:32,480 Notable name, and we get rid of this print statement that we have before now to just print Dennis with 47 00:03:32,480 --> 00:03:33,530 a lowercase. 48 00:03:34,560 --> 00:03:35,400 So there we are. 49 00:03:35,490 --> 00:03:35,940 Dennis. 50 00:03:38,500 --> 00:03:38,960 All right. 51 00:03:39,310 --> 00:03:45,080 So now you have seen how no pointer exception works and how you can force one. 52 00:03:45,100 --> 00:03:48,640 You also have seen how multiples work in Kotlin. 53 00:03:48,910 --> 00:03:53,070 And there's one last thing that I want to show you, but it will not make sense. 54 00:03:53,080 --> 00:03:58,450 You know, it will make more sense once we get into objects and variables. 55 00:03:58,660 --> 00:04:08,050 But I just want to very quickly show you that you can use the safe call operator in a chain. 56 00:04:08,560 --> 00:04:12,580 So here we are using a chain safe call, so to speak. 57 00:04:12,760 --> 00:04:16,820 So let's say we have a class called user and we create an object of it. 58 00:04:16,839 --> 00:04:23,830 There is a way for so the user can have a wife, which is also of a class or of a type. 59 00:04:24,100 --> 00:04:26,440 And then this wife has an h. 60 00:04:26,770 --> 00:04:34,660 So what we can do is we can use a chain safe call here, for example, checking if the user is empty. 61 00:04:35,020 --> 00:04:38,550 And then also checking if the user's wife is empty. 62 00:04:38,560 --> 00:04:39,880 So if it's null or not. 63 00:04:40,270 --> 00:04:43,600 Okay, so if that's the case, then assign a value of zero. 64 00:04:43,930 --> 00:04:49,570 So as I said, this only makes sense once you understand the concept of object oriented programming. 65 00:04:49,570 --> 00:04:54,340 But if you come from another programming language, that will make now sense already. 66 00:04:54,610 --> 00:05:00,760 But otherwise, I think it makes sense to go into object oriented programming, which we will do in 67 00:05:00,880 --> 00:05:01,840 the next video. 68 00:05:01,840 --> 00:05:06,100 So the next thing that we're going to look at is actually classes and objects. 69 00:05:06,400 --> 00:05:14,320 And this is a little much for now, but I just wanted to show you this in order to complete this section 70 00:05:14,500 --> 00:05:17,620 or this lecture for multiples in Portland. 71 00:05:18,160 --> 00:05:18,580 All right. 72 00:05:18,820 --> 00:05:24,940 So I'd say, let's go to the next video where we're going to check out object oriented programming and 73 00:05:24,940 --> 00:05:26,530 how to create our own classes.