<X> is the genreic type declaration. It tells the compiler that this method uses X as the name of generic type. So, when you try to actually call this method with, for example, String, X will be substituted with String.
See this for more detail: https://docs.oracle.com/javase/tutorial ... thods.html
If you like our products and services, please help us by posting your review here.
According to given program Constructor accept different generic(K,V) type than getDuplicateHolder(X). Than how come if we call the constructor of PlaceHolder with (X,X) will compile successfully. In my point of view there should be error on line 4. Please clarify.
K and V are just the names given to the types of the two parameters. They are not actual parameter types. You can certainly choose to pass same types. By using two different names, you are allowing the class to use two different types. In other words, the type of the second parameter doesn't have to be the same as the type of the first. But it can be if you want.
If you like our products and services, please help us by posting your review here.