1

00:00:00,840  -->  00:00:02,310
It does them all for the affliction.

2

00:00:02,310  -->  00:00:03,660
We have two classes.

3

00:00:03,690  -->  00:00:10,560
One is called the refl. demo and it is a main class on has been appropriately named I and the other

4

00:00:10,560  -->  00:00:12,480
one is called as a user of dot Jawa.

5

00:00:12,600  -->  00:00:20,120
So both of these classes are either in the GBM package so refl. do more as a main class and written

6

00:00:20,220  -->  00:00:22,230
refl. them or we have the main method.

7

00:00:22,710  -->  00:00:24,810
And there are things that we are testing here.

8

00:00:24,840  -->  00:00:31,320
So there are two methods for Budapest's one is called as demo class object access.

9

00:00:32,400  -->  00:00:39,880
So as the name suggests this particular method is used to demonstrate accessing class object so there

10

00:00:39,880  -->  00:00:42,010
were three ways to access class objects.

11

00:00:42,020  -->  00:00:42,490
Unreal.

12

00:00:42,550  -->  00:00:47,730
And we'll be looking at all three of them and we will also see how the Mad-Eye information in the class

13

00:00:47,730  -->  00:00:50,230
object can be accessed.

14

00:00:50,520  -->  00:00:54,450
And the second method is Karlos demo code reflection.

15

00:00:54,450  -->  00:01:00,590
And here we will explore more reflection properties for reflection features.

16

00:01:01,290  -->  00:01:06,390
So we will demonstrate instance creation and method invocation using the class object.

17

00:01:06,600  -->  00:01:07,460
So the class object.

18

00:01:07,460  -->  00:01:08,850
Here is the input.

19

00:01:09,090  -->  00:01:13,870
So that's what we are going to test here and use and our July is pretty simple.

20

00:01:14,070  -->  00:01:21,900
We are already familiar with this class so it has all these fields and it has no constructor and it

21

00:01:21,900  -->  00:01:28,110
also has this constructor which has all these parameters on initialises the fields and there are two

22

00:01:28,110  -->  00:01:28,500
methods.

23

00:01:28,500  -->  00:01:33,570
One is called a save weblink and the other is both bookmark review with some parameters here.

24

00:01:33,930  -->  00:01:37,970
But let's not worry about all of that because that's not relevant here.

25

00:01:38,460  -->  00:01:41,940
And just wandered into Boullion.

26

00:01:42,210  -->  00:01:43,660
So let's go back.

27

00:01:44,190  -->  00:01:47,970
So both these classes are available in the resource section for download.

28

00:01:48,390  -->  00:01:52,080
So let's just look at what we have in each of these matters.

29

00:01:52,080  -->  00:01:55,770
So let's just go here first with a demo class object access.

30

00:01:56,160  -->  00:02:01,590
So the first one as accessing the class object via object reference.

31

00:02:01,590  -->  00:02:06,810
So for this we are defining this string array object and it has these three values.

32

00:02:07,170  -->  00:02:15,330
And all we are doing is just invoking since a and is also an object in Java we are invoking the get

33

00:02:15,330  -->  00:02:20,730
class method and we are just simply printing or to get name.

34

00:02:21,060  -->  00:02:26,790
Now the second thing we are testing is the Arctic farming method and the class.

35

00:02:26,970  -->  00:02:29,370
So we are passing the fully qualified name here.

36

00:02:29,400  -->  00:02:33,360
After that off the user class which is also in JVM.

37

00:02:33,390  -->  00:02:39,630
So we are passing the fully qualified name on we are loading the class and we are printing all the information

38

00:02:39,720  -->  00:02:44,220
at least some of the important ones like what did we miss with that it's an interface or not.

39

00:02:44,430  -->  00:02:50,160
If there are any interfaces that this particular class user is in stone is implementing.

40

00:02:50,760  -->  00:02:56,910
And also the superclass here getting the superclass off user and printing its name.

41

00:02:57,480  -->  00:02:58,100
OK.

42

00:02:58,140  -->  00:03:01,960
Now the third one here there is one additional test that we are doing.

43

00:03:02,370  -->  00:03:06,020
We know that Glassdoor foreign for named does not work with primitives.

44

00:03:06,030  -->  00:03:12,620
So here we have a primitive here here and this word at runtime.

45

00:03:12,620  -->  00:03:17,580
This would throw an exception called class not one exception as was discussed.

46

00:03:17,610  -->  00:03:21,180
So the congruity comes here and brings this message.

47

00:03:21,180  -->  00:03:26,890
And finally there Doc class the class nutritious approaches tested here so we ain't dog class which

48

00:03:27,080  -->  00:03:29,870
is a class object and we are simply printing the name.

49

00:03:30,210  -->  00:03:35,430
So that's the first method and here is a second letter to the second method we are placing a class object

50

00:03:35,430  -->  00:03:36,360
here.

51

00:03:36,480  -->  00:03:41,700
So we are getting the class object using the foreign name approach and we are simply passing it here

52

00:03:41,760  -->  00:03:42,520
.

53

00:03:43,470  -->  00:03:47,700
And all we are doing is we are creating a new instance here.

54

00:03:47,700  -->  00:03:52,970
So on the class object this object we are calling this method call new instance.

55

00:03:53,070  -->  00:04:00,870
And in order to do that the user class must have a default constructor and that's the reason for having

56

00:04:00,870  -->  00:04:02,430
this constructor here.

57

00:04:02,430  -->  00:04:06,090
It should be there.

58

00:04:06,760  -->  00:04:14,040
Now once we do that we are invoking this method Corylus get declared methods and it contains all the

59

00:04:14,040  -->  00:04:16,610
methods in the class.

60

00:04:16,650  -->  00:04:17,070
OK.

61

00:04:17,130  -->  00:04:25,370
And so I couldn't send off all the method objects or here and method object is from the dot dot Langhart

62

00:04:25,380  -->  00:04:27,250
reflect package.

63

00:04:27,840  -->  00:04:29,660
And we are printing the names.

64

00:04:29,700  -->  00:04:33,540
And here we are making use of the white glass object.

65

00:04:33,540  -->  00:04:36,040
So we are simply saying why not glass.

66

00:04:36,150  -->  00:04:42,720
And if this particular method in the in the current iteration if it has we are calling the return type

67

00:04:42,720  -->  00:04:48,750
method and get returned by returns that the class object corresponding to the return type and if it

68

00:04:48,780  -->  00:04:54,420
equals the white class or a wider class which means that the class object responding to why don't we

69

00:04:54,420  -->  00:04:58,100
simply print dispatch it message method or can type as wide.

70

00:04:58,380  -->  00:05:00,530
So one of the methods has a void.

71

00:05:01,010  -->  00:05:04,880
It can type on in here get declared constructors.

72

00:05:04,890  -->  00:05:09,780
So disorder gets on the constructors and each construct it is basically an object.

73

00:05:10,140  -->  00:05:13,160
Once again from the Java Langhart reflect.

74

00:05:13,470  -->  00:05:18,280
And here we are getting one particular constructor.

75

00:05:18,300  -->  00:05:25,770
The constructor that does that for fetching is based on the number of barometers and the type of the

76

00:05:25,770  -->  00:05:29,500
parameters and basically the be on the type of the parameters.

77

00:05:29,610  -->  00:05:37,980
So if you look at this etches get declared constructor has an array of class objects are being passed

78

00:05:37,980  -->  00:05:38,610
here.

79

00:05:38,910  -->  00:05:39,220
OK.

80

00:05:39,240  -->  00:05:42,030
So it's a virus parameter.

81

00:05:42,300  -->  00:05:47,400
So based on that we get the constructor that we need and then we are creating a new instance of that

82

00:05:47,400  -->  00:05:47,640
.

83

00:05:47,850  -->  00:05:51,830
And we are passing all the values for example here it is anti-abort glass.

84

00:05:51,930  -->  00:05:57,440
The first parameter so we are passing this value 101 on the second parameter is name that Hurleys email

85

00:05:57,490  -->  00:05:57,550
.

86

00:05:57,580  -->  00:06:02,180
And so we are passing all the corresponding values that we need to pass.

87

00:06:02,220  -->  00:06:05,330
And here we are fetching a method and invoking it.

88

00:06:05,610  -->  00:06:08,570
So previously we are fetching a concept around in working it.

89

00:06:08,730  -->  00:06:10,740
Here you are fetching a method only milking it.

90

00:06:10,980  -->  00:06:18,660
And all we do is we in the matter get declared method on the class reference variable and we are saying

91

00:06:18,660  -->  00:06:24,810
that we need this method call see weblink and we are also specifying the parameter types here.

92

00:06:24,810  -->  00:06:25,820
String not grass.

93

00:06:25,810  -->  00:06:27,230
Another one is string dark glass.

94

00:06:27,240  -->  00:06:31,620
So if you go back here has string parameters.

95

00:06:31,640  -->  00:06:34,630
So that's what we are saying we need that particular method.

96

00:06:34,830  -->  00:06:36,960
OK so this get declared better.

97

00:06:36,990  -->  00:06:42,960
As for getting one particular matter get declared constructor as for fetching one particular constructor

98

00:06:43,260  -->  00:06:45,260
and the way you walk and method is.

99

00:06:45,450  -->  00:06:52,430
So you have the method object here just call in matter and you need to pass this user object.

100

00:06:52,500  -->  00:07:00,180
You need to pass this use object that was created earlier and we need to pass the values also.

101

00:07:00,180  -->  00:07:00,940
So we are passing.

102

00:07:00,930  -->  00:07:08,030
Do I use one of them as the host name and the other one as say rebeling is some idea.

103

00:07:08,100  -->  00:07:09,690
Sorry that you are an Teicher.

104

00:07:09,810  -->  00:07:11,830
So you're passing those values here.

105

00:07:12,340  -->  00:07:16,050
And this is returning some value.

106

00:07:16,230  -->  00:07:19,770
So Doc ralliers are off and working that is being printed here.

107

00:07:20,220  -->  00:07:21,450
So that's about it here.

108

00:07:21,450  -->  00:07:29,630
So let's just go ahead and run this program and look at the values too.

109

00:07:29,870  -->  00:07:33,180
So let's look at this.

110

00:07:33,270  -->  00:07:34,050
So here it is.

111

00:07:34,050  -->  00:07:35,570
We are printing this.

112

00:07:35,760  -->  00:07:41,850
This is using the Glasman getting the class object we are the object reference and object reference

113

00:07:41,850  -->  00:07:43,480
is basically a string array.

114

00:07:43,680  -->  00:07:46,050
So it's printing the name.

115

00:07:46,050  -->  00:07:47,680
So this is the name that's getting printed.

116

00:07:47,700  -->  00:07:52,200
So since it's an array single dimension an array we have this squared record.

117

00:07:52,380  -->  00:07:54,680
And since it's a string that it contains.

118

00:07:54,720  -->  00:08:00,480
So we have this string class preceded by an L as mentioned earlier and a semicolon.

119

00:08:00,480  -->  00:08:02,100
So that's the first one.

120

00:08:02,130  -->  00:08:08,050
Next we are using the start for a new method.

121

00:08:08,320  -->  00:08:12,720
And we are leading the class here and we are printing the name here.

122

00:08:12,720  -->  00:08:13,700
Class not get me.

123

00:08:13,740  -->  00:08:19,390
Which gives the name of the fully qualified name off the user class.

124

00:08:19,440  -->  00:08:20,390
Is it an interface.

125

00:08:20,400  -->  00:08:23,220
No number of interface it implements.

126

00:08:23,220  -->  00:08:25,520
No it doesn't implement any interfaces.

127

00:08:25,800  -->  00:08:30,870
And what is a superclass superclass is there is only one class which is it's not excluding any other

128

00:08:30,870  -->  00:08:31,730
class.

129

00:08:31,770  -->  00:08:37,100
So the only class it extends as the object bus underspending its name here.

130

00:08:38,100  -->  00:08:43,330
Now here we are trying to load a primitive using for name which we know doesn't work.

131

00:08:43,560  -->  00:08:50,040
So the control goes into the catch block here and brings this message glass not found exception to class

132

00:08:50,040  -->  00:08:51,870
dart for me not get me.

133

00:08:52,110  -->  00:08:54,000
So that's just one type of message.

134

00:08:54,420  -->  00:09:02,180
And here we are printing using the class to access the class object and we are printing its name.

135

00:09:02,190  -->  00:09:04,270
And here it is.

136

00:09:04,290  -->  00:09:05,690
It just prints it.

137

00:09:06,090  -->  00:09:09,540
That's it because it's a primitive.

138

00:09:09,550  -->  00:09:12,940
Know let's move into the second method which is a demo called reflection.

139

00:09:13,710  -->  00:09:17,320
And here a new object is created.

140

00:09:18,270  -->  00:09:22,670
And so the object name the variable name is object.

141

00:09:22,710  -->  00:09:26,970
And we are getting we are getting it's get using get Glasby and getting the class object and we are

142

00:09:27,060  -->  00:09:28,900
once again simply printing it.

143

00:09:29,260  -->  00:09:29,490
OK.

144

00:09:29,490  -->  00:09:32,520
So for I'm the class object we are creating an object.

145

00:09:32,730  -->  00:09:35,870
But then from the object we are getting the class object one more time.

146

00:09:35,900  -->  00:09:41,580
And just printing its name just to demonstrate all of this.

147

00:09:41,580  -->  00:09:49,410
So if you go down here which says object don't get class as this is the name of the class of this particular

148

00:09:49,410  -->  00:09:50,620
object.

149

00:09:50,640  -->  00:09:51,480
Now let's.

150

00:09:51,480  -->  00:09:57,930
Next as we have printing out all the methods shown here are declared methods and they are ignoring the

151

00:09:57,930  -->  00:09:59,300
get named method here.

152

00:09:59,310  -->  00:10:03,060
So it's printing to matter say a weblink was bookmark review.

153

00:10:03,570  -->  00:10:03,850
OK.

154

00:10:03,870  -->  00:10:06,840
And one of the methods post-Bush Marco Rubio has

155

00:10:09,760  -->  00:10:11,850
a right as the return type.

156

00:10:12,060  -->  00:10:17,390
So it goes into this if condition this if statement executes.

157

00:10:17,700  -->  00:10:22,470
It has a true value and it prints this statement.

158

00:10:22,470  -->  00:10:27,000
Next is we are printing all the constructors and we are breaking the name.

159

00:10:27,000  -->  00:10:32,370
Name is simply the user here for both of them are numbered alphabet I mean girls.

160

00:10:32,370  -->  00:10:36,840
So there is a method called Get barometer types on in where we are invoking that document.

161

00:10:36,830  -->  00:10:43,170
So on the first iteration or just the default constructor and the second it's the second constructor

162

00:10:43,170  -->  00:10:48,180
which had five parameters.

163

00:10:48,180  -->  00:10:58,590
And finally here we are invoking the method we are creating an instance using the instance of user using

164

00:10:58,590  -->  00:11:03,180
it using this constructor and then we are also getting though the method.

165

00:11:03,180  -->  00:11:09,210
This particular method called Save eyeblink and invoking it but passing the user instance here.

166

00:11:09,570  -->  00:11:15,140
And so it has this particular method has some print statements on it's getting printed and simply printing

167

00:11:15,150  -->  00:11:20,040
older the values passed here the parameter values.

168

00:11:20,520  -->  00:11:28,040
And finally the result of invoking save eyeblink that it can take is basically a boolean and it truly

169

00:11:28,040  -->  00:11:29,900
is getting printed here.

170

00:11:30,000  -->  00:11:35,600
So that's about that's about the reflection the more that we have.

171

00:11:36,060  -->  00:11:43,290
And one thing I want to mention as a reflection is definitely slower compared to non-HD reflection court

172

00:11:43,290  -->  00:11:43,760
.

173

00:11:43,770  -->  00:11:50,100
So for example if you're creating an all if you're creating objects using reflection and if you also

174

00:11:50,100  -->  00:11:53,690
compare it if you create the same object be it using non-HD reflection.

175

00:11:53,700  -->  00:11:59,270
So you're using the new Nuki keyword then definitely in the non-definition code will be slightly faster

176

00:11:59,860  -->  00:12:02,080
but a reflection is also useful.

177

00:12:02,100  -->  00:12:04,930
It needs to be used but it's just that it is a bitch.

178

00:12:04,980  -->  00:12:06,610
It is kind of slower.

179

00:12:06,760  -->  00:12:14,790
And so you want to be really careful if your code is going to be frequently used and you have and you

180

00:12:14,790  -->  00:12:16,400
have the reflection code there.

181

00:12:16,470  -->  00:12:22,860
So if it is being used in a very frequently used code and application or surface performance intensive

182

00:12:22,860  -->  00:12:25,780
then you need to be careful about that.

183

00:12:25,860  -->  00:12:29,320
Maybe you don't want to use Reflection in those parts of the code.

184

00:12:29,520  -->  00:12:33,750
So so just to exercise caution be careful.

185

00:12:34,380  -->  00:12:35,970
OK so that's about it.

186

00:12:35,970  -->  00:12:41,900
So that's refl. demo and we have a strict pretty much everything that we have learned.

187

00:12:42,180  -->  00:12:42,810
Thank you.

188

00:12:42,990  -->  00:12:44,310
And happy coding.
