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