Hi there. 2
Welcome back on this is Molinaro. 3
So now we are going to do the demo for bonded. 4
OK. 5
And a new motor car bonded while cars husband are just in the genetics to mock us. 6
OK. 7
So now let's go ahead and look at the code. 8
So we are going to look at this method cardless display. 9
We have seen it in the lecture but did we were using bookmark as the upper bone. 10
But here it is number so that display at that is a harmless method. 11
All it does is displays the elements of the booklets. 12
OK that's what we're doing here. 13
And the for loop we are adding to the list. 14
We are displaying the element each element here. 15
So we are using this excellence key what God gives us the flexibility to invoke it with either a list 16
of number or list of any type of number like in this tough interger. 17
OK so now because the bonus number we can also invoke one of the methods of it directly and we won't 18
have any Schuss. 19
So this is a harmless scenario and so we need to work cut on the invariant property and this gives us 20
that flexibility. 21
And this is a producer off the know that extends only produces data. 22
So if we try to consume data then we get decomposition. 23
You are limited in dentally uses the argument that uses the class level type parameter. 24
So because of that we cannot do this. 25
Only thing is we can argue we can pass a null value so we can do that. 26
Now if I make this super It means that it can consume data. 27
OK. 28
You know with the uncommon this we won't have the compilation error anymore. 29
So that is fine because it is consuming data. 30
But here we are getting a compilation error on that because here the pipe is number OK it is fine if 31
we pass a list off number but we know that this kind of super It can also be passed is supertype like 32
a lost object. 33
OK so that element would be object. 34
So if we make this object here then we are good. 35
But we we should not be come's producing that also could not produce data should only consume data as 36
we have seen in that recommendation. 37
So we should not be doing that. 38
So here are two year back. 39
So let me just go ahead and grandis go back. 40
So we are looking at twice here once here passing a list on and dejour unwanted stuff. 41
So if you run it. 42
So its husbanding the end granules and then it is printing the double on use. 43
Okay. 44
So that's the nice thing. 45
And one more thing is the scene Mattel can also be represented and this meant using a genetic method 46
. 47
Okay here is the genetic method. 48
So it can be done in that we set it up as introductory. 49
So here this is not a genetic matter it is just a bicarb type only a wild card type is being used because 50
there is no type parameter here as we can see. 51
But this one it just does the same thing here the type barometer extends a number and we are using a 52
list of B and we are still in the aliments and it will give us the exact same book. 53
You can try it out later when the thing is here we have a compilation error because this boater duplicate 54
methods on thats because it is it at runtime but on time all this GeneDx examination will be will be 55
removed. 56
So all of this will be to more on both of them are the exact same methods so they are not there it's 57
not method overloading were discarded earlier or. 58
So I mean just common this out. 59
The only thing is you might ask which of the two approaches should be used and that we will see later 60
. 61
But the main thing is if the type but amygdala is used only once here in the method declaration then 62
this is before it but if it is used multiple times let's say once in the return type and once here or 63
so only in the multiple times only in the matter parameterless then it would go for a genetic method 64
. 65
OK. 66
Because you can reuse this so there is a dependency between in the in the matter declaration dependency 67
across in the method declaration across the method parameters on that it and BYB are just the method 68
parameters because it's being reused here. 69
So that's why you want to do it but if it is used only once then this is not how but later at the end 70
of the lecture we will also look at some brief notes on that. 71
So that's not so let's go back to me on Coman this woman to come here. 72
So here we are invoking this agregate with you momentarily. 73
So basically I could get to be looked at the aggregate regarding the previous wissen. 74
So here you're passing the list into list and a list. 75
And we are also passing a nominalist which is declared here iron all the elements from both these lists 76
are added into the nominalist so we're good at getting it. 77
So if we go here to get with consumer on here is the aggregate method which we have seen earlier but 78
there we used a genetic Mettler this was from the bottom of the previous demos. 79
So we are using most wanted list on list. 80
The only thing this year. 81
Everything is off seemed. 82
But here because. 83
Because we are doing it this way we can how we can pass different types of elements. 84
So L-1 for anyone we can pass a list of integer. 85
And for that we can pass and this stuff double or whatever it is. 86
So here it is a generic Mathare as you can see that is a pipe barometer. 87
And this is an upper bonded wild card but the ball is either here or the bone is the iron. 88
Here we are using. 89
We are assuming that the torso we are using is super. 90
Here are the stupid Amato's. 91
It is excellence. 92
Ken here we are adding the elements and do all three costarring L-1 elements than any two elements. 93
By looking at all the material. 94
So we are consuming data on how super is used here. 95
So again I named it as agregate with concealer because if we do not do that then we get a duplicate 96
both of them would be deep or duplicate. 97
I just named this as aggregate. 98
So let's go back and let's just run it around here that is the nominalist. 99
So it has all the six elements. 100
Now I'm in here you have the same method can also be expressed using genetic markers. 101
So most of the methods can be exposed in this way. 102
In this case we are using the tree which is this fun for the consumer and even is extending E3 and also 103
is extending E3 but E3 is being used only once here. 104
So I think this is portable. 105
This is preferable about using the wild card. 106
Does this approach is profitable. 107
I know it is also much more clear because this is the exchange and this is excellence and this is super 108
. 109
So it is much more crowded also. 110
So this is a profitable approach for this because that type element is not being used here is not being 111
used more than once here and this is okay. 112
So. 113
So lets go back. 114
So thats what that non-intellectual you also get some commonly used methods from collections. 115
Let's look at some of them here. 116
So one of them is at Ohlemacher iron. 117
We know that at all amateur basically and the elements here in the collection and we're using super 118
for that. 119
So this is the method from the Collections class. 120
So this is the all and we are passing through in Google use here and we are adding them into this other 121
list off object. 122
Marjorie Howard or it IX's the pipe is in the pipe in Ford is in danger. 123
And here we are having the lower Bonner's integer and integer here. 124
So that's sort it is so because lower bonus because the lower bar is integer we can pass a collection 125
of integer or a collection of object. 126
So that's what we are doing we are passing a list of object. 127
So basically the the type argument are used is the most specific subtype across the type arguments. 128
So this is object indeed on an Dejah. 129
So because we are using super head smartly they used the integers as the argument against the pipe argument 130
. 131
So they use the most specific. 132
Now copy as copies from the dhaba here from the second but go to source in this list. 133
So copy would copy everything and this and get that image. 134
So from the starting from zero to lament it would copy everything and go into the same index positions 135
. 136
And if this list happens to be a bigger slice then all the remaining elements after the elements are 137
copied from here will be retained. 138
OK they they will have the same values as this. 139
Let's look at the matter here. 140
OK so this is super because it's consuming data on sources externes we look at that. 141
And once again it's a genetic McChord. 142
So we go back Howard on it. 143
So you're passing a double list on a list so that type in court isn't up and it's more specifics update 144
. 145
And here we are just simply printing the last of the copy operation. 146
And the third one is that this joint operation which we have also seen. 147
So we are passing disjoined both the Los Angeles on the list and it uses an unbonded Why not simply 148
print and go to accrue if the if there are no common elements between the two options. 149
It's an unwonted. 150
Because we really don't care what the pipe is in here and disposed on here. 151
In the past. 152
So I me run this. 153
So here we are after the copy operation all the elements are copied at the beginning. 154
But the nominalist also had some double elements here. 155
Okay. 156
The last three elements. 157
So they are retained as it is and they design and operation here as a dining group because one is an 158
interest on one is a double list so you cannot have any common elements. 159
So that's not and we also to replace Mathare if you recall now for the replacement there I end or just 160
a simple replace method which is pretty much like the replace method and the replace all method in the 161
collections. 162
So all that is doing is go back. 163
This is the matter Qurei bliss all this is a generic method but there is also a question here which 164
uses the super but replace all book producing and consuming data. 165
So it should be like this. 166
OK. 167
Now let's let's just serialist. 168
So this in this list. 169
So this is all value on this is the new value and the old values present we need to replace it. 170
So let me just move back. 171
So here is the list and we are saying or replace all the values of eleven point forty four. 172
So there are two instances seven point eleven point five on here on it. 173
It is printing again with 44. 174
OK Art but replace all the math and I just want to show you that it can also be done in this way like 175
using a wildcard type. 176
OK with this thing a lot wanted card type but you shouldn't be doing this in this case it is fine because 177
you are using only the equals method and the object. 178
But if this happens to be something like a bookmark or a number then and if you using some methods specific 179
to that lower bone then we can run into cross-current exceptions because it can also be passed a number 180
. 181
In this case it is fine because we're only using the term object. 182
Equals is a matter Klym object. 183
But as we said if we are both producing and consuming data then we need to use eques then we need to 184
use equal match. 185
Here we're producing the data on here using the segment that we are consuming data. 186
So that's about that. 187
And finally here is yet here I just wanted to show this. 188
This is an idealist. 189
So this is one way in which our eldest is using it. 190
So this is a constructor and an idealist is taking this collection and copies all elements of this collection 191
into the audience. 192
We are using extents but e is actually the barometer of the cost the cost of that parameter. 193
OK. 194
So this again. 195
So in this case because of that the the number is the class level type parameter. 196
OK. 197
But we can also pass a list of integer. 198
OK a list of indigenes can be passed because here the matter is this extents number right. 199
It says excellence member you could be number because a number is being passed as type argument. 200
And if it is number which means that we can also invoke this constructor using a collection or number 201
or any updates on that's what we are doing here. 202
So I bonded wild card is helping us do that. 203
So this is just an example. 204
So that's about it for now. 205
And this court is available in the resources section. 206
Let me also just discuss a little bit about how when to use Spight type barometers versus who are you 207
carps which we also discussed earlier. 208
But you have to look at critically a bit more. 209
So let's say there were some sites not okay like we discussed earlier many methods can be declared using 210
just wild cards are using generic methods. 211
So the question is which of the two approaches should we play for. 212
We should go for genetic matter of the same type Hamacher appears multiple times in the method declaration 213
but does dependency exist and long pipes off one or more Meklit parameters and are then you can. 214
For instance in the automatic Collections class same type but I'm eager It appears more than once. 215
Among the parameters. 216
So far this genetic matter it is appropriate. 217
Similarly here is another method from the collections class. 218
She had also the same type parameter appears more than once. 219
As part of the method return type and once as part of the motet parameter but of the same type parameter 220
is not going great at multiple times then go forward. 221
What else is there to Cinematheque which we have seen earlier under-equipped the best dirt using a white 222
wildcard as a type parameter would have appeared only once. 223
Finally this is a disappointment there from the collections class which we have seen earlier this also 224
unbonded wild card is better. 225
And this gives book collections can have different types of elements. 226
So if we a person using a genetic method B would have to use different parameters put a beating on me 227
once in them at the declaration. 228
So wildcard is the way to go. 229
So that's about it. 230
I hope you enjoyed learning about Willcocks. 231
It should help you to write better library code. 232
Thank you.