What meaning has <E> on the code Collection<E>?
What meaning has <E> on the code Collection<E> ?
Share
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.
It’s the use of generics. Check this intro out. And then don’t forget to read this tutorial.
An excerpt follows (which compares the use of a cast versus the use of generics):
For example, the interface of a List is
This means you can build a list whose contents are all of the same explicit type (not only of type Object), even if you have defined the type yourself. So, if you create a Name class you can write
and then fill it with Name instances and directly retrieve Name instances from it without having to cast or otherwise worry about it because you’ll always get either a Name instance or null back, never an instance of a different type.
More importantly, you cannot insert anything different from a Name instance in such a List, because it will fail at compile time.