问题描述
我在写类的工作就像。
看起来
公共FilterReadableByteChannel实现的ReadableByteChannel { //我应该允许空通道?
公共FilterReadableByteChannel(最终的ReadableByteChannel通道){
// ...
}
}
和我发现,无论和许可证空
来源。
*参数的基本输入流中,或LT; code>空< / code>如果
*该实例是没有基础流被创建。
问:
- 对此有任何实际的原因是什么?
- 有没有改变底层源创建后的任何可能的情况下?
我知道为什么不呢?
可能是一个答案,但我想知道,如果有,为什么原来的API设计这样做的任何理由。
Yes. Even if not declared as such, classes Filter*Stream
are conceptually abstract classes. IOW, they only exist to be extended. Subclasses could need to provide the in
or out
parameters after construction (example: lazily; on first real use), and Filter*Stream
gives them this flexibility.
The obvious case is when source is initially null
. Other cases that come to my mind are: 1. Creating a subclass of Filter*Stream
that acts as a selector. IOW, has several underlying streams and methods to switch from one to the other. 2. Creating a subclass of FilterInputStream
that concatenates different InputStream
s. 3. Creating a subclass of FilterOutputStream
that splits output into different OutputStream
s.
Yes: generality.
这篇关于空源FilterInputStream中的/ FilterOutputStream中的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!