java - Poison a blocking queue when the queue type contains a generic -


i have type, mytype<t> contains generic type t. have blocking queue of type blockingqueue<mytype<t>>. send "end-of-stream" markers queue, i.e. poison pills, issue cannot instantiated poison pill because of generic type. there way around this?

you should able create one.

class mytype<t> {       private blockingqueue<mytype<t>> q = new arrayblockingqueue<>(10);     // poison pill signal end of queue.     public static final mytype<?> pill = new mytype<>();      /**      * special private constructor pill creation.      */     private mytype() {      }      public boolean queueclosed() {         return q.peek() == pill;     } } 

if have own constructors add private constructor no parameters.


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -