Abhishek KumarSoni wrote:Could you please explain me one more thing whar is difference between a wildcart<?> and a type parameter
Well, it's a bit of a broad question, but I can point out few differences in bullets:
Wildcards can have both upper and lower bounds, while type parameters can have only upper bounds.Wildcards cannot have multiple bounds, whereas type parameters can have multiple bounds - <T extends Comparable<T> & Serializable>
The choice of which one to use will depend upon what you want to do. For example, if you just want a method to iterate over any
Collection and print the contents, then using wildcards would suffice. However, if you are concerned about a particular type you get, or you want to enforce more type safety, you would use a type parameter. To explain on that further, a
Collection<T> is a homogenous collection of a particular type, that is not known at compile tie, whereas, a
Collection<?> is a heterogenous collection. That means you don't know what type you will get from it. It might contains at the same time a
String, an
Integer, and a
Date.
As I said, it's quite a broad topic, you would be better off going through some tutorials on generics:
Here is the good place to start. Then when you want to have a detailed understanding of this topic, then I would suggest you to spend some time on
Java Generics FAQs.