[concurrency-interest] LinkedBlockingQueue does notthrowClassCastException

Ernst, Matthias matthias.ernst at coremedia.com
Tue Apr 17 05:21:53 EDT 2007


>        ClassCastException - if the class of the specified element
>        prevents it from being added to this queue

You conflate "carries an <Integer> type parameter" with "prevents Strings from being added".

The combination of the implementations of your test, LinkedBlockingQueue and Java generics does NOT prevent an element of a different class to be added. Thus no ClassCastException is thrown. Thus you need to remove CCE from your test and it will be green. It's as simple as that.

> public class lbqTest {
>   LinkedBlockingQueue q;

Better yet, write LinkedBlockingQueue<Integer> here and put @ExpectDoesNotCompile onto your test.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20070417/34fbed96/attachment.html 

More information about the Concurrency-interest mailing list