Hi there this is going to do you know understand the motivation for the need for bondable cuts that 2
make our ice flexible and in this lesson they will get into the details of bonded Walcott's And we'll 3
also look at recommendations on grant to use them Dumay will be done in the follow up lesson and it's 4
going to be a long lesson but an important one. 5
Let's begin with upper bondable cuts in the previous lesson. 6
We mentioned that in certain harmless scenarios we're type safety is not a concern invariant property 7
can be restrictive. 8
We set up on solution is to use genetic methods and we looked at it in the Dematteo of the solution 9
was to use upper bondable cuts. 10
And here is an example. 11
The key word excellence is used and it can be read as a list of some subtype off book Walk. 12
What it means is a video of such an upper bonded wild card type can be assigned to a list of bookmark 13
on our list of book on our list of movie. 14
Notice that even though we said it is a list off some subtype of bookmarked it can still be assigned 15
a list of bookmarks. 16
So subtype would also imply that every type is this a pipe of the supper table. 17
Art is helping us to work on the inflexibility of invariants and we know that due to invariants we cannot 18
do this. 19
That is a list of book cannot be assigned to a list of bookmarks. 20
On here it is the harmless display method that displays all the bookmarks in the input list and this 21
method can be in more. 22
But list off a bookmark or list off book or list of all the art list overbilling. 23
And we also know that the same method can also be expressed using generic method. 24
In this way not that unbonded wildcard simply implies that object is the ball. 25
That is if you have a list of unbonded Volkart then we can assign it a list of object or list or any 26
such type of object. 27
Which means you can assign a list of anything as object as a supertype of all types as we just saw an 28
unbonded Volkart is also an upper bonded ballcock. 29
But that object as an invisible Baun and due to this upper bondable card also has the same compiler 30
types if the restrictions as an unwanted Wilcott. 31
That is we cannot invoke moppets that use class level type parameters with any arguments except none 32
. 33
So if the wildcard type is something like an idealist then we cannot invoke the augmented as the add 34
method use asset class level type parameter. 35
You can invoke it only by passing in this way pipes if he's unsure at compile time extension. 36
This means that you can only do stuff like this by the input parameter x as a producer of data but does 37
not and you need that is within the method the cannot access methods like ACTA But this up of underbite 38
Godfrey church gives us the flexibility when it comes to passing off arguments. 39
Also just keep in mind that all that genetic notation that you see here will not be there at runtime 40
. 41
It would be addressed off by the compiler. 42
It is only to ensure that we are making the right invocations on right assignments both in the calling 43
code as well as the matter. 44
So at runtime the wildcard byte will simply be lost. 45
Now if we want to consume the dot then we need to go with no what wanted wildcard. 46
And we discussed it briefly in the previous season and here is an example. 47
In the case of upper bonded wild card we use the P word extents on here. 48
We use the key super and we can read it as list off some supertype of bookmark for a pointer wildcard 49
. 50
It was list off some subtype of a bookmark. 51
So because we are using a super keyword what it means is a list of a bookmark at the lower one can be 52
assigned a list of bookmark or a list of objects as object is a supertype of bookmark not dactylic subtype 53
. 54
In case of supertype you every type is a supertype of Xserve. 55
Hence we are able to assign a list of bookmarks here. 56
We however cannot assign not a list of books on another list of Maulvi as book and movie are subtypes 57
of book. 58
Doing so will give a compiler error. 59
It's got to be a bookmark or it's super nice on here is a compiler restriction that would make an louvered 60
bonded card type act as a consumer of data under the same time ensures that compile time types if the 61
is not compromised. 62
So the router is VIGEN equipment words that use class level type parameter only if argument is off longer 63
bonder type or one of its subtypes here as an example which we also saw in the previous listen the method 64
is Nimbus aggregate hundred use a silver bonded Whatcott type good book mark castable. 65
So this method as we can see can be invoked with an idealist or bookmark or we can also invoke it with 66
an other list of object. 67
And but then the method has the lower bonders bookmark we can and will add that and pass a bookmark 68
object or any of its subtypes like book or movie objects. 69
So basically input list is consuming data. 70
In the earlier example of the splintered input list was producing data. 71
So here in booklist Attis a consumer on superspy would put into that. 72
But if you use exc. word then input list x as a producer but not on the data just not the pipes if bees 73
also respected here as the more specific argument that can be passed would be endless Stoffe bookmark 74
which can contain bookmark or any of its type objects. 75
This is the same aggregate method with the same method parameter type. 76
The statements show that from the input list then we get an element it stipes should be off type object 77
. 78
So full statement is invalid. 79
Well second is valid. 80
False statement is invalid because if the method is in with a list of object then we get a class exception 81
as object can not be trusted to bookmen unless we insert an explicit cast not duck. 82
Lol what Baun is only for wildcards. 83
It cannot be used with type parameters and when this occurs it applies to both generic types as well 84
as generic methods. 85
You know that extends keyword applies to parameters too. 86
One other thing to note is that a wildcard can how only single upper are single lower bound. 87
You know the type parameters and generic types on generic methods can have multiple bunchy on here is 88
an important effective dollar item which is used bonded wildcards to increase API flexibility. 89
We already discussed it and we said that was the motivation for using bonded carts are also generic 90
methods. 91
So if you're writing AB ice then you would want to see as bonded Woodcock's can be used for method parameters 92
from a design standpoint. 93
It would be great to use them whenever possible. 94
Let's look at the specific suggestions from this item. 95
If the input parametrized type produces data then we should use a put bondable cark. 96
You saw this in the display method earlier and we already know this too. 97
If input parameters type consumes data then use lower bonded wildcard. 98
And you saw this in the aggregate Materne earlier. 99
If input parametrized type produces data on you don't know or don't care what the pipe argument is in 100
the invoking code. 101
Then use unbonded wildcard. 102
Just note that here we are seeing producing data support unbonded are upper bondable cards. 103
Our producers are like we discussed earlier unbonded wild card is also an upper bondable card. 104
It is just that it uses a more generic bound object so unbonded an upper bound it producers by no unbonded 105
wild card is it concealment. 106
And here is an interesting thing. 107
If parameterize type Axel's book producer and consumer then you'll need to use an exact match. 108
That is something like and less off book back then because you use white box. 109
For instance. 110
Cannot use operable hundred wild card as extents does not allow us to consume data right due to pipes 111
or frustration. 112
Similarly we can't use Lammert bonded well card as the problem will be with producing data. 113
We know that within the method the input object that syndicalist can consume the louver bone on any 114
of its subtypes. 115
But when it comes to producing data there is no indeed that it would produce only more bone or any of 116
its updates. 117
That's because since the method can be invoked bit list off some supertype of the lower bound. 118
It can also contain some supertype objects which can need do class const exceptions at runtime so it 119
needs to be exact match Niguel list of bookmarks. 120
That way you know that the list can always consume unproduced only bookmark objects or one of what's 121
next. 122
Finally in case you're having trouble remembering a bought producer and consumer then you can use this 123
mnemonic packs which stands for user extents and guns you are super gay. 124
So keep packs in mind. 125
Also just note that this concept of producer and consumer is also often referred to as get put in. 126
You can get for producing the DA while consuming get put principle also says if bought get and book 127
happen then exact match is needed. 128
Now let's quickly look at some real producer consumer amateur declarations from the Jaguar ocotillo 129
collections costs here the comment method is add on which is a generic method and it acts on the specified 130
elements to the specified collection see which is the parameter. 131
So collection is going to consume elements are enhanced. 132
Super. 133
What is your extra copy method. 134
It copies all the elements in source list in the destination list destination list is the hospital magor 135
so socialist. 136
Here is the producer and hence excellence. 137
Q What is yours. 138
Why the destination list. 139
Is the consumer on hence super. 140
Q What is your next it's a dis dramaturg under-treated answer group. 141
If they do and book collections have more elements in common on here and unbonded wild card is used 142
because we really don't care about the type of elements in the collection model work. 143
They are producers of data that is only the elements are iterated and unknown data is added into the 144
collections. 145
So data is just compare. 146
But no data is entered into the collections. 147
So unbonded wild wildcards should be used for such cases. 148
Our next is replace on Widgery places on occurrences of one value in a less that and value hit an exact 149
match as needed as just as put producing as well as consuming data. 150
For instance here is the relevant code fragment from this method. 151
Here is the list as being it record it checks if the current element is equal to only 1. 152
So the list is acting as a producer here and if the current element is equal to all valid then it is 153
being replaced bit Newble thereby making the list act as a consumer as the statement that uses class 154
global parameters. 155
So in this case we need to use an exact match on wildcards should not be used. 156
As discussed earlier in the follow up lesson we will leave them all under or we will see how these methods 157
can be actually invoked. 158
So that's all for now. 159
Just to summarize. 160
Remember Doc bonded while costs can make your API very flexible and not that extends to what is used 161
when you want to produce data. 162
Well Superguy word is used when you want to consume data. 163
All right then. 164
Thank you. 165
See you in the demo.