High they are not asked to have them all off. 2
What we learned in the previous mess and so forth does them all a new class called JENNETT extra more 3
has been created in the package column Dawk semantics quare.generics. 4
OK now here is the main class on we are going to fill. 5
So in the last lesson the Lubet agenda in is called Ask container. 6
And we also saw that there was a generic class called store which implements container. 7
So let's just go ahead and do that Fossel Let's create those generic types Husna to create a generic 8
interface and Bynner created here 9
and type B 10
can also be what element but that's fine. 11
And so that's the container 12
. 13
So you see this a 14
and it's also right to get your return type would be geg 15
set. 16
So those are the two genetic types. 17
Now let's go ahead and instantiate store. 18
I'm Fussell let's create a stored off strength that storm strength sisig can dinner that have inspired 19
be dinner because that's the interface and we need to do an interface. 20
We know that going string store and let's use that diamond notation so that that type is automatically 21
inferred 22
shaila and that's printed code space. 23
Be this not getting on this. 24
Prince giallo OK. 25
So that's what we have. 26
And we know that genetics gives us the advantage of compile time by periphery. 27
Right. 28
So let's just go and cried to an integer here. 29
And as you can see it says the Methot sex string in that type can a string is not applicable for the 30
arguments. 31
OK so it is giving us a compilation error right here at compilation time. 32
OK so that's the main benefit of genetics right. 33
It is commonly taught now that's created since it is genetics. 34
We can create another instance of store but with the different type argument. 35
So let's make it string sort of integer. 36
That's called it. 37
Do your store get in the mood got 38
it run this is going to print one. 39
OK. 40
Now let's create a slightly more complicated instance. 41
Let's make this list of integer k shift all its import data and its consciousness store. 42
And once again the type is automatically inferred here and let's call it let's draw or 43
not set. 44
Let's use our Ariz class say eyes lest one do tree k and let's just say let's store not get here and 45
this is going to print 1 2 and 3. 46
OK. 47
So that's how we can create instances. 48
Now you might have a question. 49
So what exactly is happening under the hood. 50
Is it going to somehow create three instances of store for these three. 51
I mean three start store process for when we are working with these different arguments. 52
OK. 53
Three store classes or is it simply creating store instances but somehow in the store instance you know 54
the type would be string. 55
In this case and in this case the object what how. 56
Integer as the type for those variables here. 57
OK and in this case it could be left off in two years. 58
So we might guess if something like that is happening but that's not happening. 59
OK so what is going to happen as a feature cart type eraser is being used here. 60
And if you recall we said that Gen X is up your compile time concept which means that Gen X does not 61
apply at runtime at runtime. 62
There is no generates I don't care. 63
And what does that mean. 64
It means that the compiler basically uses this feature called Fraizer. 65
OK. 66
And as the name suggests it is going to it is that type C compiler is going to remove this type. 67
OK so in this case it's a pipe argument. 68
It's going to strip off this and it's just going to write as if this thing is not there and get a bite 69
code. 70
Similarly here also in this generic types since we are saying pipe eraser It is going to remove this 71
type. 72
OK and same here also it's going to strip this off and it's going to erase this off. 73
That's why it's called IP razor. 74
And for this be it were replaced by object. 75
In this particular case here also object. 76
See here. 77
OK it's going to replace it object. 78
Next we will also look at something called bonded parameters on there. 79
This beacon extends some other glass in which case the clasp can be written here in this case you can 80
think that the extents object in fact be extents object in this case internally. 81
So it would replace that object. 82
But if we extend something else then that would be stored here but that people look at it easier. 83
But basically Typee treasure is that's all there is to type in Asia. 84
So that's one thing that is going to happen. 85
It's going to raise the type from both the parameterize types as well as from the type barometers. 86
So it really object everything will be object here. 87
And this whole thing will be stripped off but so this thing will also get stripped off. 88
But here when we are getting in working to get the dirt get met that is going to return an object because 89
here this is going to be replaced by object. 90
And even the get out here is going to done an object since we are going to do it in an object. 91
But in this particular invocation statement a string is being expected. 92
So the the compiler would insert a cast here it would insert a string here like this and it would insert 93
an integer here. 94
I know over here it would insert a list of integer. 95
OK so the compiler is going to do that. 96
So compiler is doing two things. 97
It is going to erase off all the pipes all the generics notations. 98
And it is going to explicitly insert gas. 99
OK. 100
But for us the advantages the court is looking clean. 101
But the court will not be that clean because it's going to insert gas and that is a magic pipe that 102
compiler is doing for us. 103
So that is what is going to happen under the hood. 104
So all the pipes are getting erased and also costs are being inserted. 105
That's how it's going to work. 106
It might be confusing. 107
Definitely it would be confusing. 108
But that's on as happening with under the hood. 109
OK. 110
That S-type eraser. 111
But we will look at Tipler later also towards the end of the chapter. 112
But I think it will give you a good idea. 113
That's why I wanted to discuss it now so that you would know what is actually happening under the hood 114
. 115
OK. 116
Now there is a restriction that we also discussed about one of the restrictions was doc type argument 117
can not be primitive. 118
So let's try that out. 119
Now as you can see we get a compiler error. 120
OK. 121
So that's not possible. 122
And there was also a second restriction that we looked at that says that type parameter cannot be used 123
in a static context. 124
Right. 125
So if you go here and if we make this Dodik it's going to get a compilation error cannot make a start 126
reference to the non-static type. 127
So that's what it is. 128
So you cannot even do that. 129
So those are the two restrictions that we have. 130
And one other thing with this subtyping is sometimes you can if you want to you can also let's say if 131
you want to make this a string then in that case you see it says add unimplemented metrics the type 132
store must implement the inherited abstract method container holstering not such string. 133
So it says that we need to implement this method called set which has a parameter string. 134
So the moment we change this we need to implement some new methods. 135
So let's go ahead and just this and as you can see some new methods got added which have strength. 136
So just because we are saying that we want to implement content offspring then that would make us implement 137
these methods. 138
OK so that's what it is. 139
But if you make it contain it on string then here over here the type argument has to be either string 140
or a should not be anything in which case this needs to be remote. 141
In which case it just cardless the wrong type. 142
It's just it just means that the argument is not there. 143
So it has to be either for doctype or it has to be string just because B how can you get off string 144
here. 145
OK so that's the restriction that people how you can also create out just make it some other type and 146
you can also try it out for instance if you make a string here condense it off string as you can see 147
here. 148
It gives a compilation error. 149
It says cannot infer type arguments for start and that's because we are using integer rather than string 150
. 151
So it's got to be a string on one off its subtypes Audix it's got to be a rock pipe and we will also 152
discuss it by later which is basically doesn't have any arguments but it is dangerous to do that and 153
we will discuss that later. 154
So just wanted to highlight that. 155
So let me just go ahead and make this the very Modise auto created methods. 156
So that's about what we learned earlier. 157
But let's also go ahead and create a few more but I'm impressed by a few more instances just as it's 158
created a list off member number as a class and the set list. 159
New Order list and Khrushchev. 160
Oh and and yes we can I add an ember instance of number or one off it's spazzes subprocess. 161
And this is one of the subclauses integer. 162
So we can do dot on that say 1. 163
OK. 164
So in this list are Ls to be an odd number or we can add one ifits subtype objects. 165
Similarly double it is also a subtype off number. 166
So you can just say double and to do OK but you cannot add anything else because we are using generics 167
. 168
So you cannot do something like this strain. 169
And it's going to do on the compile time type safety kicks in and says you cannot do that. 170
The method out of number in that type list off number is is not applicable for the argument string because 171
we are passing a number here and I admit the third one now. 172
Because of this it well how. 173
Number Aztek type. 174
And if we try to add a string object it's going to give us this combination error. 175
OK. 176
That's the issue. 177
That's the thing. 178
And that's the benefit that we have. 179
But give it a bit generics. 180
Now let's also do something with Arrius 181
say you list off too. 182
So it does list on either side. 183
OK. 184
So what it means is you can store any of the list implementations list as an interface and we can store 185
any off its implementations and just say zero on that door New Artist. 186
OK another just object is being stored at the zero position and one that can store that's a linked list 187
and that is one game we can do got a whole game. 188
So that's because we can store any list. 189
OK. 190
Now if you make this an idealist then B how. 191
I mean we don't get any competition at her. 192
OK what this means is we want to store only our A-list within this array. 193
But we are also starting ringless but it did not give us a completion order. 194
But if we run it it's going to give this or a story exception game which means that at runtime we are 195
getting this exception and that's not very good because the type safety is not enforced or compile time 196
but at runtime. 197
OK. 198
That we are going to discuss later. 199
But I just wanted to just show you that if you create like an artist here or something you can store 200
either that instance of doc type or I want to get subtypes but back then and then if you're trying to 201
store something as we are getting a compiler error OK. 202
So the error is being shown at compile time itself whereas in case of an NRA we can see that we are 203
not having any issue at compile time because we are supposed to store only our oldest objects. 204
And here we are storing l'Anglaise. 205
But in case of an array the typesafe B is being enforced only at runtime behere the types is enforced 206
at compile time in case of generics. 207
But we are as it is enforced at runtime and that we will also discuss later when we are discussing invariants 208
. 209
But just wanted to highlight that here. 210
So that's about it. 211
Thank you. 212
And the court is available in the resources section happy coding