About Question enthuware.ocpjp.v7.2.1292 :
Moderator: admin
-
- Posts: 16
- Joined: Fri Sep 04, 2015 5:06 pm
- Contact:
About Question enthuware.ocpjp.v7.2.1292 :
Why cant "Queue container = new PriorityQueue();" be used?
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1292 :
The first sentence of the explanation explains exactly what you are asking. I am quoting it here for your convenience,
Since the return type of getRequestToProcess() method is Request, and the return statement does not have a cast, it means that container must be a typed generic collection that returns Request objects only.
-
- Posts: 18
- Joined: Sun Jun 21, 2015 2:56 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1292 :
If there would be such answer:
Would it be correct? it would compile, but PriorityQueue would throw exception while adding an element to nonempty queue.Queue<Request> container = new PriorityQueue<Request>();
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1292 :
Yes, it would have been valid. Yes, it is possible for an exception to be thrown if the code is not used correctly but that is irrelevant for the question.
HTH,
Paul.
HTH,
Paul.
Who is online
Users browsing this forum: No registered users and 7 guests