I am wrapping the BlockingQueue to make it accept null values as shown in the code I post below. The line that reads "if (val instanceof NullValue) " gives me "Illegal generic type for instanceof". val is a variable of type Object, and NullValue is a class that derives from Object. Why am I getting this error? Granted I am using generics, but not on this line. I would understand it if I had written "if (val instanceof E)" but in this case I don't think this error makes sense. Could it be a compiler bug?
public class PipelineQueue<E extends AbstractDataType>
implements InputBuffer<E>, OutputBuffer<E> {
private ArrayBlockingQueue instance;
private class NullValue {
};
@Override
public E take() throws InterruptedException {
Object val = instance.take();
if (val instanceof NullValue) {
return null;
} else {
return (E) val;
}
}
public int size() {
return instance.size();
}
public int remainingCapacity() {
return instance.remainingCapacity();
}
@Override
public void put(E e) throws InterruptedException {
if (e == null) {
instance.put(new NullValue());
} else {
instance.put(e);
}
}
@Override
public String toString() {
return instance.toString();
}
public Iterator iterator() {
return instance.iterator();
}
}