Java Reflection Summary

https://drive.google.com/drive/u/0/folders/0B5rDe4aQDBhyMkR2TWVkUl9hMzA

There are two documents to illustrate the java's reflection (including the relationship between the reflection and generic)

Advertisements

generic

Firstly we meet compile error when we use the generic type in programming, so we have the generic imported in java
71657575-3357-43CF-9F0D-1D897D0BEC7E

Then we define our own generic type, the constructor don't need the T type
786EC65F-55F0-4988-9AD1-5F1828BD8156

When we derive class we have two method, one is to specify the generic type, the other one is to ignore itusing the following method, we will use @SuppressWarning("unchecked");
0E21BA4A-B576-4163-B423-E35019C9FDAF

Then the key is to understand there is no generic class
B58D08AF-7C29-4F01-B58B-F8949B82272

Then if our collections' value type is not determined, how to do it … ? comes
0932A84A-AB50-477B-947B-6E12B81B185F

but the ? cannot add the element since the type has not been determined
6B9F8373-2903-44D2-83F0-E9AC6455133F

The the ? can work with the extends key word. But since we still don't know the specific type of the collections' element's type, so we still cannot add element in our generic container
FAF6A398-B4DA-4CC2-AFAF-DE089F3BB7

Not only we can set the restriction on passing the parameter, we also can set the restriction when we define a class
0CE53747-91CA-465B-8323-169A5CDB9

But sometimes we want to be function oriented, so we need our function to be compatible to some other type, so we need set generic method in our program, it is very similar to the cpp
4894947E-3AA7-4BF4-9C23-A23B79C23E18

But we still cannot confuse our compiler
8373FB54-A12A-4271-8CF6-C763EC4E8
28CE4540-20C1-4132-B166-E7CA0408C29E

Since the ? can also implement a really high level of generic, so the generic method and ? parameter can implement the same function    —   the key of conversion between these two style is to understand that the ? is generic so lots of different parameter type can get    but some feature will be lost   
First we should understand the difference 
 DBF358D7-9D48-4CB5-B549-3BECEA8BBD19B1A91013-8108-4EC8-9446-2D33730E5AE0

The type inference of generic type can be used in constructor function
A7F404A5-23E5-42EB-AE32-017F657DBD14

Then we will introduce the super key word in java generic — TO MAKE SURE THE TYPE INFORMATION WE NEED IS REALLY CLEAR 
4F727B1C-0B8E-4C90-BFF6-F08E21E0FE58

Why we need this specific super grammer, to make the type inference as precise as possible
2B0774AB-7767-43F4-8D7B-E17899D7E8A8

Avoid the pitfall when we have to overload the method 
449FE188-9BC3-4B72-9BB8-B872FFB76F20

The type earsion, how to avoid this pitfall when we use the java generic programming 
42C1CB1B-AC8C-4A33-9FFE-15D6DFEBED61
CE446BC4-9594-44F3-A509-33D278DAFA8E

How to understand the java's generic design principal understand the upper bound and lower bound the upper bound is extend    THE SUPER IS USED SET THE LOWER BOUND (THAT IS THE SPECIFIC CHILD TYPE)

Java Copy

Generally we use the clone as the shallow copy, if we want to do the deep copy, we will use the serialize method
BUT THE OVERRIDE CAN CHANGE THE RETURN TYPE, THIS IS WHY WE CAN AVOID THE CLONE METHOD JUST RETURN THE MOST PREVIOUS'S OBJECT TYPE

5AF2A24D-C553-4B33-A7C8-7745E18123B

1391B3E9-7DC6-43A0-B2FC-55124AA28929

Java 方法重载原则

两同 两小 一大

两同:方法名相同   形参列表相同

两小:子类的返回值类型应该比父类的返回值类型更小或者相等
           子类声明抛出的异常应该父类声明抛出的异常更小

一大: 子类方法的访问权限应该比父类方法的访问权限更大或者相等