No, there is no such write-only interface implemented by BlockingQueue.
You can indicate your intent by exposing in-projection BlockingQueue<in MyCommand>, however it won’t prevent consuming values from that queue.
If you only need to put values to the queue from the outside, you can expose just put method itself:
class ClassWithQueue {
private val queue = BlockingQueue<MyCommand>()
// either as a property
public val enqueue = { cmd: MyCommand -> queue.put(cmd) }
// or as a method
public fun enqueue(cmd: MyCommand) { queue.put(cmd) }
}
// either as a property
public val enqueue = { cmd: MyCommand -> queue.put(cmd) }
// or as a method
public fun enqueue(cmd: MyCommand) { queue.put(cmd) }
I’ve never used a “function”-property like this. Is there any benefit compared to traditional methods?