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