- Firstly we meet compile error when we use the generic type in programming, so we have the generic imported in java
- Then we define our own generic type, the constructor don’t need the T type
- 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”);
- Then the key is to understand there is no generic class
- Then if our collections’ value type is not determined, how to do it … ? comes
- but the ? cannot add the element since the type has not been determined
- 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
- Not only we can set the restriction on passing the parameter, we also can set the restriction when we define a class
- 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
- But we still cannot confuse our compiler
- 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
- The type inference of generic type can be used in constructor function
- Then we will introduce the super key word in java generic — TO MAKE SURE THE TYPE INFORMATION WE NEED IS REALLY CLEAR
- Why we need this specific super grammer, to make the type inference as precise as possible
- Avoid the pitfall when we have to overload the method
- The type earsion, how to avoid this pitfall when we use the java generic programming
- 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)