I have a question about the List class. From what I understand List is a class deriving from the Collection class. My problem is that when I read examples on the internet, it says for example List < Entry > entries;
I’m having slight difficulties understand what that actually means? Entry is supposed to be another class but I do not understand how it works. I read it as, create list of type Entry and store it in entries, is that correct? Just to clarify my question, what confuses me most is the Entry part of it, if it’s another class how does that make the list function? IS it the object created in the class Entry which describes the Type of list it is? An example would be great.
I apologize if I have not been clear enough, any help much appreciated. I’m talking about Java in this particular case.
It’s called Generics. The Entry is the type argument.
List<Entry>means “a list which contains Entry objects”.Worked example:
And you cannot do this:
because the object
wrongTypeObjectis not anEntry.Good article here:
http://en.wikipedia.org/wiki/Generics_in_Java