I am relatively new to the concept of generics. I am working on a project that simulates a registrars office at a school. It has a Clerk, Student and RegistrarSimulator class. In the Clerk class it is supposed to have a reference to a Queue in the constructor and that is then supposed to be stored in a ConcurrentLinkedQueue. In the API the ConcurrentLinkedQueue constructor is:
Isn't the API documentation clear on that point? Or do you mean the bit about extends E? In which case start with the Java™ Tutorials: use ctrl-F for generics and look for wildcards. It means the Collection contains the same type "E" or one of its sub-classes.
so the what this constructor takes is a Collection whose objects extend E so in my example I could give it an arraylist of fruit, or a hashset of pears(provided that Pear extends Fruit) or any collection that has Fruit as a superclass. So:
pears = new ArrayList<Pear>(); //Pear extends Fruit
fruits = new ConcurrentLinkedQueue<Fruit>(pears); //because pears is a Collection of Pear objects which would extend E(which stands for Fruit in this case)
well the second one would only be used if you already have a list of people in line, which if you ask me wouldn't make sense. The first one is usually the one you want, but if you had any code I could say for sure
Joined: Oct 17, 2009
I dont have any code yet... but at first there will be no one in line and then after a certain amount of time the line will start to accumulate. So i will go with the first constructor.