Both the class and the constructor can be shared on their own, that is, each has its own type parameters. for example
class A<T> { <S>A(S s){} }
To call a constructor with all explicit type arguments
new <String>A<Integer>("abc");
Think of it this way: A<Integer> is a concrete class, and <String>A is a concrete constructor.
Due to type inference, we can omit the type argument for the constructor
new A<Integer>("abc"); // S=String is inferred
The type argument for the class can also be omitted and output using the syntax "diamond" ( <> )
A<Integer> a = new A<>("abc"); // T=Integer is inferred, as well as S=String
I wrote a (long) post on this subject - fooobar.com/questions/830135 / ...
ZhongYu
source share