It is pretty obvious that like an ArrayList is a container full of items of type “Generics”.
How can a class make use of Generics except being a container? Any common usages?
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
One simple example is
Comparable<T>That allows you to compare one person with another in a natural way.
Likewise there’s
Comparator<T>:That allows you to compare any two people in a specific way. Neither of those interfaces is about a “container”.
Then there are types like
Future<V>, representing the promise of a value of typeVat some point in the future (basically an asynchronous operation). Now you could think of this as a kind of container, but it’s not a collection…Fundamentally, generics are useful whenever you have an operation or type which is usefully parameterized by type (possibly with constraints) in order to maintain type safety, but can work with various different type arguments for that type parameter.