1

00:00:01,050  -->  00:00:05,530
High they're not us look at something called bonded by parameter.

2

00:00:05,590  -->  00:00:07,350
We know what the type parameter is.

3

00:00:07,350  -->  00:00:10,130
And we also know what a genetic type is.

4

00:00:10,260  -->  00:00:17,040
We know that genetic types gives the client code the flexibility to instantiate them that any type argument

5

00:00:17,050  -->  00:00:17,350
.

6

00:00:17,640  -->  00:00:23,640
So the problem lies with that plan but sometimes we might want to put some restriction on the kind code

7

00:00:24,150  -->  00:00:30,630
with regards to what type argument they can use while instantiating a generic like unglue that we can

8

00:00:30,630  -->  00:00:39,270
use it bownde a parameter the Bonder type an amateur is simply a parameter with one or more box.

9

00:00:39,360  -->  00:00:40,460
And here is the syntax.

10

00:00:40,830  -->  00:00:46,920
We have the byte barometer followed by the word extents which is then followed by one or more bonds

11

00:00:47,370  -->  00:00:49,810
which are separated by Ambersons symbol.

12

00:00:50,700  -->  00:00:55,190
On Here is an example of how the generic class called GenericsDemo excitable.

13

00:00:55,580  -->  00:00:59,310
And here the bomb for the type parameter is next.

14

00:00:59,340  -->  00:01:05,670
This means that the bite argument has to be a list or one of its subtypes.

15

00:01:06,270  -->  00:01:12,480
So we can have something like this with genetics that is instantiated using that type argument list

16

00:01:14,010  -->  00:01:20,430
or we can also have genetics to instantiate or to use in some types of list such as an idealist are

17

00:01:20,430  -->  00:01:22,160
linguists.

18

00:01:22,500  -->  00:01:27,970
But if we do this we get a compiler error as collection Binoy is not a populist.

19

00:01:28,270  -->  00:01:30,460
We know that it is a supertype awfullest.

20

00:01:30,690  -->  00:01:37,380
So it's got to be either the bone itself or one of its supples on a dime of this letter will also be

21

00:01:37,380  -->  00:01:44,390
a shock to this although as we saw in the syntax a bike parameter can have more than one bone.

22

00:01:44,430  -->  00:01:50,470
In practice you will mostly encounter only single boner by parameters.

23

00:01:51,370  -->  00:01:57,390
Now apart from restricting the glance on repipe arguments they can use a bone also allows its class

24

00:01:57,600  -->  00:02:01,140
to access them but that's defined by.

25

00:02:01,140  -->  00:02:04,760
For instance if we consider this example here we have the generic class.

26

00:02:04,770  -->  00:02:06,770
Generics don't have them either.

27

00:02:06,780  -->  00:02:12,150
Go with the parameter columnist's under stype is the type parameter.

28

00:02:12,180  -->  00:02:18,060
Now within this matter we are invoking the seismic third on the list immediately and when we do that

29

00:02:18,060  -->  00:02:19,460
we get a compiler error.

30

00:02:19,700  -->  00:02:26,600
And that's because here we are using only that type parameter uncompiled her just does not know whether

31

00:02:26,600  -->  00:02:31,340
the type argument would include the method size or not.

32

00:02:32,430  -->  00:02:39,030
But if you use a bounded type parameter where d extends the list interface then compiler will not have

33

00:02:39,030  -->  00:02:43,620
any problem as sys method is declared in the list interface.

34

00:02:43,770  -->  00:02:48,530
So that's a benefit you get in using bonce you can access their methods.

35

00:02:48,990  -->  00:02:55,770
But note that it's got to be a method in the bonus's if it is a method specific to one off it's subtypes

36

00:02:56,190  -->  00:02:58,640
then we once again get a compiler error.

37

00:02:58,840  -->  00:03:01,210
Now that has to do with type in Asia.

38

00:03:01,590  -->  00:03:04,130
We discussed pipe behavior in an earlier lesson.

39

00:03:04,330  -->  00:03:12,240
There we said that in the bytecode compiler would replace the type parameter with the pipe object right

40

00:03:12,240  -->  00:03:12,660
.

41

00:03:12,670  -->  00:03:18,390
However in this particular case since the type parameter extensive Baun the pipe parameter would be

42

00:03:18,390  -->  00:03:21,240
replaced by the bond itself.

43

00:03:21,240  -->  00:03:27,750
So in this example compiler will replace beat with list so the code within the government that can only

44

00:03:27,750  -->  00:03:31,230
use methods declared and then listen interface.

45

00:03:31,410  -->  00:03:37,080
If you have to use the methods declared in a subtype awfullest then you need to typecast to that particular

46

00:03:37,080  -->  00:03:37,880
supply.

47

00:03:38,220  -->  00:03:44,120
Otherwise you will get a compiler error on herer bones that are considered valid.

48

00:03:44,130  -->  00:03:51,820
A bomb can be a class or it can also be an interface not you look at the syntax Veals the keyword extents

49

00:03:51,820  -->  00:03:52,330
.

50

00:03:52,500  -->  00:03:59,060
That is we see some type parameter extend some ball and that applies to interface too.

51

00:03:59,640  -->  00:04:05,040
So you cannot use a word like implements just because the bond is an interface.

52

00:04:05,040  -->  00:04:08,200
So the keyword X does here works for both classes.

53

00:04:08,230  -->  00:04:16,280
USB plus interfaces next to bone can also be an enim which we will discuss later on finally.

54

00:04:16,290  -->  00:04:22,280
It can also be it Behrami Christ like so it can be that I'm type 2.

55

00:04:22,310  -->  00:04:23,490
And here's an example.

56

00:04:23,730  -->  00:04:24,750
Here the Bondy's it.

57

00:04:24,770  -->  00:04:26,170
But I mean cross-slide.

58

00:04:26,580  -->  00:04:34,080
Later we tried to look at more practical example of this unhidden bones that are invalid.

59

00:04:34,440  -->  00:04:36,970
It Baun cannot be primitive.

60

00:04:37,530  -->  00:04:45,560
No recall that type argument cannot also be a primitive case of primitives are not in love at all and

61

00:04:45,560  -->  00:04:47,990
a boat cannot be an update.

62

00:04:48,240  -->  00:04:49,910
So just keep that in mind.

63

00:04:51,210  -->  00:04:55,980
Undernote a few more specifics that we need to be Aguiar off with respect to bonder type parameters

64

00:04:55,980  -->  00:04:56,610
.

65

00:04:56,610  -->  00:05:03,090
First one is that if the type parameter has multiple bonce then the type argument must be a subtype

66

00:05:03,270  -->  00:05:06,920
of all the specified bonce.

67

00:05:06,930  -->  00:05:14,060
For instance in this class definition the right barometer extends both the list and Serializable interfaces

68

00:05:14,070  -->  00:05:15,000
.

69

00:05:15,630  -->  00:05:23,170
And this is the first instantiation would be invalid as the type argument list is not Issel type of

70

00:05:23,180  -->  00:05:24,440
serializable.

71

00:05:24,870  -->  00:05:29,510
It is fine with the Fussball but not with the Serializable interface.

72

00:05:29,700  -->  00:05:36,270
But the second instantiation is valid as other list is a subtype of both list as well as serializable

73

00:05:36,270  -->  00:05:38,080
.

74

00:05:38,310  -->  00:05:42,680
Next off the bonce is a class then it must be specified first.

75

00:05:42,750  -->  00:05:45,170
Otherwise you get a compiler error.

76

00:05:46,260  -->  00:05:51,490
No offense Bondies a class then remaining balance must be interfaces.

77

00:05:51,540  -->  00:05:56,900
In other words you cannot have more than one class among the list of bombs.

78

00:05:56,970  -->  00:06:04,350
Not that you can hold more than one interface and you can how only interfaces to not the bounds of final

79

00:06:04,350  -->  00:06:06,330
class on any name.

80

00:06:06,330  -->  00:06:09,720
Then the pipe argument would be the bonus.

81

00:06:10,320  -->  00:06:18,560
That's because final class does not have a subclass on enum is essentially any final class too.

82

00:06:18,810  -->  00:06:21,680
So those are specifics that we need to be aware of.

83

00:06:21,680  -->  00:06:28,780
Now let's go ahead and do a very quick demo of some of the stuff you saw in this lesson.

84

00:06:28,870  -->  00:06:34,290
OK here we are in the genetics demo class and we're going to test most of the stuff that we have seen

85

00:06:34,290  -->  00:06:35,150
in the lecture.

86

00:06:35,310  -->  00:06:42,030
So first thing yes let's just go ahead and make this a genetic type which should be under to make it

87

00:06:42,030  -->  00:06:46,360
bounded by parameter in its extent.

88

00:06:46,410  -->  00:06:49,510
That's what we have seen in the lecture.

89

00:06:50,280  -->  00:06:54,870
And here let's instantiate that generics them all.

90

00:06:54,900  -->  00:07:01,790
Now it is a Democrat state next to the last one.

91

00:07:02,040  -->  00:07:03,970
OK so that is valid.

92

00:07:04,200  -->  00:07:10,500
So it has to be a list so the list is up bound so it has to be the Bonder itself or one of its subtypes

93

00:07:10,500  -->  00:07:11,070
.

94

00:07:11,070  -->  00:07:20,490
So that is good and this is also good on our list but as we have seen it as collection then we get compilation

95

00:07:20,490  -->  00:07:21,100
error.

96

00:07:21,330  -->  00:07:25,030
That's because collection is a supertype off the bomb.

97

00:07:25,110  -->  00:07:26,640
In this case.

98

00:07:26,640  -->  00:07:29,920
OK so that's one thing that we looked at.

99

00:07:30,000  -->  00:07:35,320
Next we also said that we can access the methods and the bug.

100

00:07:35,490  -->  00:07:44,620
So if you do this here we have the there look at this and here that by parameter is steep.

101

00:07:45,000  -->  00:07:53,700
So on we are accessing the IDE matter and the list here the variable name is just a list but we are

102

00:07:53,700  -->  00:07:57,840
trying to access the add method in the list interface.

103

00:07:57,840  -->  00:08:00,000
Now we are getting type evasion.

104

00:08:00,300  -->  00:08:04,810
The compiler will replace every instance of B with a list.

105

00:08:04,980  -->  00:08:07,200
OK that's smart the compiler does.

106

00:08:07,230  -->  00:08:07,800
Spout off.

107

00:08:07,800  -->  00:08:13,690
I put it here since in this case it would replace the type with the boundaries set.

108

00:08:13,860  -->  00:08:17,340
If the bond was not there then it would replace with object.

109

00:08:17,340  -->  00:08:20,990
So in this case it would replace with D and we are able to access augmented.

110

00:08:21,050  -->  00:08:23,390
Now remove this.

111

00:08:23,490  -->  00:08:26,960
The T.M. this.

112

00:08:27,060  -->  00:08:32,850
So in this case as you can see we get a compilation error and we cannot access the add method in the

113

00:08:32,850  -->  00:08:39,240
list any more because the compiler just doesn't know that the type argument will be and this or not

114

00:08:39,250  -->  00:08:39,490
.

115

00:08:39,650  -->  00:08:46,940
How about if we extend less than we are regarding the compiler that the add method would be there now

116

00:08:46,970  -->  00:08:47,260
.

117

00:08:47,410  -->  00:08:52,170
No in order to make it work we have to use construct like this.

118

00:08:52,170  -->  00:08:58,940
That's the only solution that we have here or we need to make it a bounded by parameter.

119

00:08:59,400  -->  00:09:03,700
Now that's one thing and let me just you know this

120

00:09:07,170  -->  00:09:09,650
.

121

00:09:10,540  -->  00:09:12,760
Then we look at a couple of invalid Bonnes.

122

00:09:12,780  -->  00:09:14,870
So this is not going to work.

123

00:09:14,890  -->  00:09:16,890
If it cannot be an array.

124

00:09:16,890  -->  00:09:20,530
Similarly it cannot be a primitive.

125

00:09:20,820  -->  00:09:23,010
So once again we get a compilation error.

126

00:09:23,640  -->  00:09:26,570
Next below get some specifics.

127

00:09:26,580  -->  00:09:30,920
One of them is when we have multiple bones like this serializable.

128

00:09:30,930  -->  00:09:33,210
So these are two interfaces.

129

00:09:33,390  -->  00:09:40,080
Then the pipe argument has to be the bone or one off its up apps on it has to be a subtype of all of

130

00:09:40,080  -->  00:09:40,860
these.

131

00:09:40,980  -->  00:09:41,430
So

132

00:09:44,860  -->  00:09:47,240
make a list.

133

00:09:47,460  -->  00:09:52,650
So this would give a compilation error because the second one is fine.

134

00:09:52,920  -->  00:09:58,110
OK so the list is fine but it is not a subtype of serializable.

135

00:09:58,200  -->  00:10:04,920
Now if you make it out a list then there is no compiler because this is a supply both.

136

00:10:04,920  -->  00:10:06,820
Both of these interfaces.

137

00:10:07,150  -->  00:10:14,220
OK so that's one of the things one of the specifics that we have seen and the next thing was you said

138

00:10:14,220  -->  00:10:19,510
that if there is a class then it's got to be the Fussball.

139

00:10:19,630  -->  00:10:21,480
OK so this is fine.

140

00:10:21,510  -->  00:10:23,700
Now let's make it like this.

141

00:10:23,940  -->  00:10:27,570
So Serializable an idealist.

142

00:10:27,770  -->  00:10:30,350
And as you can see we get a compiler error here.

143

00:10:30,450  -->  00:10:34,500
OK so that's not how I end.

144

00:10:35,220  -->  00:10:38,100
You can also how more than one class.

145

00:10:38,130  -->  00:10:40,970
Even that was mentioned.

146

00:10:40,980  -->  00:10:43,410
So you can do this.

147

00:10:43,410  -->  00:10:48,620
So even if we import this you can see we cannot utter dick.

148

00:10:48,630  -->  00:10:51,350
So we can't have two classes here.

149

00:10:51,390  -->  00:10:54,150
OK so that Sanderus for this demo.

150

00:10:54,150  -->  00:10:56,010
So we basically looked at everything.

151

00:10:56,010  -->  00:11:01,800
Now if it is a final class like string then the R-Type argument has to be the bond itself.

152

00:11:01,860  -->  00:11:03,970
So we discuss that also.

153

00:11:04,050  -->  00:11:04,950
So that's about it.

154

00:11:04,950  -->  00:11:07,820
So this court is not available in the resource section.

155

00:11:07,830  -->  00:11:08,790
It is not available.

156

00:11:08,850  -->  00:11:10,270
It's just for demonstration.

157

00:11:10,320  -->  00:11:13,940
So you can test it out and you're ready for that cert.

158

00:11:14,040  -->  00:11:14,460
Thank you
