Fruit {String toString () {"Fruit" Apple Fruit {String toString () {"Apple" Person {String toString () {"Person" ClassName <T> {"show_1" + <E> "show_2" + <T> "show_3" + <Fruit> o = ClassName <Fruit >==" show_1 demonstrates ____________________ "System. out. println ("show_2 demo ____________________" "show_3 demo ________________________"
Output:
Show_1 demo ________________________
Show_1 Fruit
Show_1 Apple
Show_2 demonstration ________________________
Show_2 Fruit
Show_2 Apple
Show_2 Person
Show_3 demonstration ________________________
Show_3 Fruit
Show_3 Apple
Show_3 Person
/* The show_2 and show_3 methods are completely equivalent. That is to say, if show_1 has no prefix <T> after T is specified as Fruit, this method can only be show_1 (Fruit object)
If you have a prefix <T> or <E>, you will tell the compiler to say: this is a new type I specified,
It has no relationship with T in the Class Object of ClassName <T>. In other words, T and show_2 in show_3
E is an effect, that is, you can geographically resolve show_3 to <E> void show_3 (E e ){~~~~~}
From what I said above ,*/
<T> you can understand it as a type declaration. Otherwise, a "T" suddenly appears in your return value and function parameters. The Compiler knows what this is and will certainly report an error, therefore, we need to understand this issue from the compiler perspective.
Just like int a. The variable a can be used later.