1

00:00:00,990  -->  00:00:07,050
Hi there now that we know why language designers came up with Benedix let's not get started with the

2

00:00:07,050  -->  00:00:09,890
basics of genetics in this lesson.

3

00:00:10,020  -->  00:00:15,660
They will look at the syntax and terminology involved with genetics and also look at few restrictions

4

00:00:15,780  -->  00:00:20,610
associated with genetics in the Allison will lead them off genetics.

5

00:00:20,760  -->  00:00:24,910
Basically we do have them all off what we learned in this lesson.

6

00:00:25,500  -->  00:00:32,590
Let's begin by looking at genetic type a genetic type is simply a class or an interface that type but

7

00:00:32,580  -->  00:00:37,740
amateur's defined in the declaration on here is the basic syntax.

8

00:00:37,740  -->  00:00:43,800
So the class name is followed by something called type parameters which are camos operator are not enclosed

9

00:00:43,800  -->  00:00:48,420
in less than greater than symbols and within the class.

10

00:00:48,420  -->  00:00:55,830
These type parameters can be used as byte for instance variables by foot barometers on local variables

11

00:00:56,160  -->  00:00:58,280
within methods are constructors.

12

00:00:58,620  -->  00:01:04,760
And also ask method root types on here as an example from the previous lesson.

13

00:01:04,890  -->  00:01:08,640
The class store uses a single byte but I'm a dirt beat.

14

00:01:08,900  -->  00:01:15,660
And as you can see despite barometer is used just the type for the instance variable A as well as method

15

00:01:15,710  -->  00:01:17,370
parameter in the center.

16

00:01:17,440  -->  00:01:21,280
And also as a return type for the get.

17

00:01:21,600  -->  00:01:23,850
So we look at for the generic type s.

18

00:01:23,880  -->  00:01:26,770
Now let's see what a parameter is this.

19

00:01:27,000  -->  00:01:31,150
And also understand some Gentex terminology here at the top.

20

00:01:31,200  -->  00:01:38,730
We have the genetic type store and we know that B here is the type barometer and is also referred to

21

00:01:38,760  -->  00:01:42,620
as a formal type barometer under the bottom.

22

00:01:42,630  -->  00:01:49,290
We can also see that for instance this off store are created for instance is a store of string that

23

00:01:49,290  -->  00:01:54,450
is a string is stored in the stored instance that a string got response to that pipe barometer.

24

00:01:54,450  -->  00:01:56,360
Be in the store class.

25

00:01:56,520  -->  00:01:59,530
The second instance is a store off date.

26

00:01:59,940  -->  00:02:07,620
Third instance is a store off list of data that is store instance stores a list containing data objects

27

00:02:08,530  -->  00:02:11,420
unfought is stored off Brooke.

28

00:02:11,460  -->  00:02:17,430
You may recall that in collections framework we did something similar to create lists of string on a

29

00:02:17,490  -->  00:02:19,800
list of integers and so on.

30

00:02:19,800  -->  00:02:23,660
So listener interface is a generic type.

31

00:02:23,730  -->  00:02:28,920
Now here the reference by store of string is referred to as it parametrized by.

32

00:02:29,460  -->  00:02:32,080
So the whole thing store followed by string.

33

00:02:32,120  -->  00:02:35,800
But then the less done greater than symbiotes is up permit race type.

34

00:02:36,010  -->  00:02:36,400
OK.

35

00:02:36,540  -->  00:02:39,360
So we have the genotype on we have the parametrized type.

36

00:02:39,460  -->  00:02:45,060
OK so just keep that in mind on just the string is referred to as type argument.

37

00:02:45,090  -->  00:02:47,530
Our actual barometer.

38

00:02:47,820  -->  00:02:53,640
Now if you recall our introduction to them at lesson in the language basic series we had similar terminology

39

00:02:54,420  -->  00:02:58,240
method parameters were also called as formal parameters.

40

00:02:58,260  -->  00:03:04,680
Well arguments passed during method invocation were referred to as actual parameters so that it was

41

00:03:04,710  -->  00:03:07,230
formal parameters are natural parameters.

42

00:03:07,230  -->  00:03:12,490
And here it has formal parameters on actual type parameters.

43

00:03:12,600  -->  00:03:19,080
Because we are dealing with types no one thing to note as in the first three instance creation statements

44

00:03:19,440  -->  00:03:23,360
we have the right argument on either side of the assignment.

45

00:03:23,830  -->  00:03:29,380
How they would in the last week meant we have the type argument on the left side and on the right we

46

00:03:29,390  -->  00:03:32,630
how M.D less than greater than symbols.

47

00:03:32,710  -->  00:03:38,420
And this is called Diamond notation and it works only from July 7 onwards.

48

00:03:38,460  -->  00:03:45,130
In this case type is automatically inferred based on the types specified on the left side.

49

00:03:45,300  -->  00:03:50,880
So it is a shorthand so soit would be elegant to use this notation.

50

00:03:50,880  -->  00:03:54,150
Now let's look at the naming conventions for type parameters.

51

00:03:54,150  -->  00:04:00,430
You should definitely use a single uppercase letters and we can also see some conventions here.

52

00:04:00,540  -->  00:04:05,180
If you are writing some kind of a collection type class then you can use an E Where.

53

00:04:05,210  -->  00:04:07,690
E is for element.

54

00:04:07,770  -->  00:04:12,650
If you're writing a map then use gay for the unbe for value.

55

00:04:13,080  -->  00:04:19,390
If a generic type is dealing with numbers then you can use an and if your agenda type is a non-color

56

00:04:19,390  -->  00:04:22,740
action and is not about numbers then you can use it.

57

00:04:22,750  -->  00:04:26,160
B B would be the common one as generally B.

58

00:04:26,160  -->  00:04:26,600
Right.

59

00:04:26,610  -->  00:04:28,600
Non collection classes.

60

00:04:29,070  -->  00:04:35,210
Typically you would have only one type parameter but if you have more than one then you can use s u

61

00:04:35,280  -->  00:04:39,890
and v for the second third and fourth types just like SUV.

62

00:04:40,530  -->  00:04:46,220
I don't think he will ever go beyond forth on even if you do you can use some other character.

63

00:04:46,290  -->  00:04:54,480
Generally you can use any legal Jawa identifier but stick to this convention and this slide shows how

64

00:04:54,490  -->  00:04:58,090
a generic type can be subduct on the left.

65

00:04:58,110  -->  00:05:01,100
We have a generic interface called container.

66

00:05:01,300  -->  00:05:01,810
Right.

67

00:05:01,890  -->  00:05:05,090
We have the genetic Glassdoor which we saw earlier.

68

00:05:05,400  -->  00:05:11,610
But in this case it implements the generic interface container on here and in an offbeat in the class

69

00:05:11,610  -->  00:05:18,860
declaration of store is basically parameterized type on we can create an instance of storing this it

70

00:05:19,620  -->  00:05:25,740
reference type is the generic interface container all the interfaces we saw in collection's framework

71

00:05:25,740  -->  00:05:31,470
API are also gentrify and you may recall that we weren't instantiating their implementations in this

72

00:05:31,470  -->  00:05:32,410
way.

73

00:05:32,550  -->  00:05:37,180
For instance you referenced type would be a list of something or not right.

74

00:05:37,200  -->  00:05:43,350
We would have something like an analyst in the demo that we will do in the next lesson we will implement

75

00:05:43,350  -->  00:05:48,300
this court and we will also look at a couple of other things around subtyping.

76

00:05:48,900  -->  00:05:53,820
This example just shows a generic class with multiple type parameters.

77

00:05:53,820  -->  00:05:58,900
If we assume that all store class works like a map then it would look something like this.

78

00:05:58,910  -->  00:06:06,540
VB What how parameters can be which will be used in different places within the classes body here can

79

00:06:06,540  -->  00:06:13,680
be are used just pipes for key and value variables and then also used as constructor parameters and

80

00:06:13,680  -->  00:06:22,200
also as written by IPS in the methods get the and get value nowness look at couple of core restrictions

81

00:06:22,290  -->  00:06:25,850
that are associated with genetics and later in the chapter.

82

00:06:25,890  -->  00:06:32,530
They will also look at few more restrictions here the restriction is that the type argument cannot be

83

00:06:32,740  -->  00:06:33,900
remedied.

84

00:06:34,410  -->  00:06:39,920
In this example the type argument is and it would give us a compiler error.

85

00:06:40,770  -->  00:06:47,130
Similarly another restriction is doc type barometer cannot be used in a static context.

86

00:06:47,580  -->  00:06:52,360
For instance it cannot be used as a type for stocktake Williams.

87

00:06:52,410  -->  00:06:58,330
Here we have a generic class called device and we can see that static variable device type has the right

88

00:06:58,350  -->  00:07:00,110
barometer B as that.

89

00:07:00,450  -->  00:07:02,450
And this is illegal.

90

00:07:02,710  -->  00:07:04,840
Lets see why this is illegal.

91

00:07:04,860  -->  00:07:05,970
Do I understand it.

92

00:07:06,090  -->  00:07:13,480
Let's assume that it is legal to define a static variable with that type barometer.

93

00:07:14,020  -->  00:07:20,070
Here we have these two statements where we are creating two instances of device in the first instance

94

00:07:20,380  -->  00:07:25,500
that type argument is smartphone while in the second that type argument is bigger.

95

00:07:26,130  -->  00:07:31,690
Another question we can have is what would be after both these statements are executed.

96

00:07:32,070  -->  00:07:34,910
Would it be smartphone or would it be pager.

97

00:07:35,640  -->  00:07:42,270
If we assume that it would be pager just because it was the last it meant to be executed then the assumptions

98

00:07:42,300  -->  00:07:49,350
made by the developer who wrote the first statement might become invalid for example double up on who

99

00:07:49,350  -->  00:07:56,400
wrote the false statement would expect the type to remain stocktake when he Bassa smartphone on some

100

00:07:56,400  -->  00:07:59,230
other code of his word expect the same.

101

00:07:59,280  -->  00:08:04,420
Now if it gets changed to a pager then it could result in some undesirable behavior.

102

00:08:04,700  -->  00:08:12,300
And that is the reason type barometer is not allowed to be used in this way since we are talking about

103

00:08:12,300  -->  00:08:14,630
stocktake context by parameter.

104

00:08:14,700  -->  00:08:19,850
Obviously cannot be used in a static method or in a static initializer.

105

00:08:20,520  -->  00:08:21,950
So thats about it for now.

106

00:08:22,140  -->  00:08:27,390
And as I mentioned earlier we will look at fuel more restrictions later after covering some relevant

107

00:08:27,390  -->  00:08:28,410
concepts.

108

00:08:28,800  -->  00:08:29,490
Thank you.

109

00:08:29,490  -->  00:08:32,220
Our next move is more of what we learned and this lesson
