Hi there this is they don't want to lose you. 2
I know let's look at what an unbounded wild card is. 3
Item number three which we saw earlier with regards to Roth pipes. 4
Also discuss us about unbonded Walcott's. 5
We know that a genetic bite through its type parameter indicates that it can be instantiated with an 6
unknown type. 7
Right here is a genetic type and it can be instantiated by using parameterized types like store of string 8
or sort of integer but a parameterized type like a generic type can also indicate that each type argument 9
can be an unknown type and that is done using a wildcard. 10
And here is an example question mark symbol here is a white card and it can be read as store off some 11
pipe. 12
What this means is the met that girl doesn't know or doesn't care whether you will get with the story 13
of straying or sort of double or start of integer Archstone or whatever. 14
Basically parameterize stripe is being gentrified here. 15
Also if you're referring to this VEIDT cart as unbonded Valcartier which means that there is also something 16
called bounded by cart and we will discuss it later in a separate lesson. 17
No dark wild card can be used only as a type argument so it cannot be used as a barometer. 18
For instance if you use it as a pipe barometer like in this example then it would be ambiguous to veto 19
the two type parameters that detached type of variable is referencing. 20
So we cannot use wildcard for it by parameter not that commonly it is used just part off type of method 21
parameters like in the case of method go here although it can be used in assignment statements. 22
It is not common to see them being used in this way. 23
Here we have stored a String instance which is assigned to a variable whose reference byte uses a wildcard 24
. 25
Just recall the store is a class we used in one of the earlier lessons and there's also part of the 26
genetics demo class. 27
One question we may have is if wildcard Jannette if I use a parameterized type then why not simply use 28
object of type argument as object as the most generic class as it is a superclass of all process and 29
hence can be assigned to any object. 30
The limitation with using object of type argument would be that you can only assign an instance that 31
also has object type argument. 32
And this has to be a property called invariants which we will discuss later but it applies to not just 33
object type but any type like string or integer if it is stored of string. 34
You can only assign is stored of string but with white card we can assign an instance of any type that 35
is storing all string Ostrov integer or anything else. 36
And here is the example we saw in the previous lessons Jim on there. 37
Rock pipes were used as parameters. 38
You may recall that this method simply returns the number of elements that are common between the two 39
in coatless. 40
Only difference here and this method is that raw types are now replaced by wildcards so that this be 41
once again how compile time type safety. 42
Now here is an important pipe see if the restriction from the compiler when using unbonded Willcocks 43
we just cannot invoke any methods on the part on the great stype. 44
Were those methods use the parameter of the class in the method parameter. 45
The only way we can invoke those methods is by passing a non-value as argument. 46
So we cannot involve them by passing any other argument. 47
And if you can't do that you get a compiler not that. 48
Here we are seeing classes parameter. 49
Later we will look at generic methods which can have their own parameters. 50
That is methods can have pyper amateurs that are completely independent of the type that armiger declared 51
at the class level. 52
So this is the restriction be how it is to ensure pipes if B for instance it is the same example we 53
saw earlier. 54
Only difference here is the statement where we are in marking the odd matter of the list. 55
This really was a compulsion at her as the add method uses sic class level type barometer for the method 56
parameters parameters did. 57
Just imagine compiler allowing us to quantify which is an Which I guess it would also allow us to add 58
a double value with the simplest Just like in the case of a rock. 59
And we once again would have the same safety issues. 60
So compiler ensures that we cannot invoke such methods but it would allow us to access methods that 61
did not use classloader parameters as method parameters and the condensed method in this class. 62
But if you do want to access methods that method parameters that how Glass-Stegall by parameters then 63
you can use generic methods or bonded wild card types both of which will be discussed later on. 64
One other thing to note here is that apart from not being able to add elements to list one or list do 65
we cannot also make any assumptions about the Bible objects that we can get out of them. 66
We do not know whether it is a string or integer or some other object. 67
If we need to know the object type then once again we need to use generic methods are bounded by the 68
courts. 69
We can also see this in the demo. 70
So let's head over to clefs for a short demo. 71
OK here we are in the genetics demo class and we are going to look at this method called just get common 72
elements called wildcard. 73
So in the previous animal we'll get this method get common elements caught little sticking to less list 74
of strengths. 75
The first one had these elements ABC and the second NBCC and all this method does as a reader and a 76
number of elements that are common between the tulis. 77
So it would be two. 78
So this meant that I was using rock types and in this method we are using wildcards unbonded wild card 79
stuff the only difference. 80
So here we are. 81
So we looked at the signature and the lecture to see it use it. 82
It uses an unbonded wild card here. 83
Everything else is same. 84
And if we run it it prints the value too. 85
OK. 86
So when you are tempted to use rock types just because you do not know or you do not care about the 87
objects and the less then you would want to use unbonded right. 88
COX So that would give you the compile time type safety guarantee. 89
OK. 90
So let's go back. 91
So that's the common way in which wild cards are used and method parameters are that are used in method 92
parameters and they are not commonly used like this in assignment statements. 93
So here we see how a container of some type will get counted. 94
If you recall it is an interface unbe or assigning a string store so String store was created and one 95
of the earlier demos here does contain on all string. 96
And we are instantiating it with a store stored implements container and we are setting the value Djala 97
. 98
And we can also move the get method. 99
So we are taking this string store not all string and we are assigning it to a container of some type 100
. 101
OK. 102
Now once this is there we really do not know what this particular object will help. 103
Ok that's why it's named some store. 104
And when we get the only thing we can do is we can assign it to object because this is the supertype 105
all process. 106
So we can assign it to this because we really do not know what this one has because it's been at off 107
some time. 108
But if you for sure know that it has an object of certain type like string in this case then you can 109
help string but unique or type construct here. 110
So that's the thing. 111
But it's not commonly used in this way. 112
So here is the stored element Java. 113
Now let's look at the third one which is a compiler restriction. 114
So here we have to list lots of integers and it has these elements 1 2 3 and 4. 115
And what we want to do as we wander past is there's less to this method called aggregate we are named 116
. 117
It's named as invalid aggregate because it is really invalid. 118
So we're passing this nice list on here and it is still here and we want to aggregate them into this 119
list. 120
So there will be added into this list. 121
So let's look at this method. 122
So we scroll down here. 123
This is the method that sonor does so these are all panoramic Rice types lists one list to unnecessary 124
. 125
So here we are trying to invoke the argument that on list 3 on our list one and then the second statement 126
and list two. 127
But the compiler is giving an error here because we cannot move these methods such methods because these 128
method this method uses a class level type parameter and we know that we cannot in those matters and 129
that is how the compiler is ensuring that safety came back we can invoke other methods like campaigns 130
or any other method which does not use. 131
It does not use class level type parameter just that we can't be we in this. 132
And if you really will only mean you can invoke is by using NULL value so if you are not here you can 133
see that there is no compulsion at all anymore. 134
And but if you're not ok with this restriction or if you're not ok with this restriction here like this 135
you really want to know what element is stored like in such cases you have to use either bounded wildcards 136
or you can use generic methods. 137
OK. 138
Our next move will look at generic methods and we would also look at this particular method with Widger 139
with generic that's where we can agree to get things set up Saunders wisdom on. 140
Thank you. 141
And this code is also available in the resource section. 142
Happy coding.