[英]Why does not Files.newByteChannel return FileChannel?
java.nio.file.Files.newByteChannel
返回SeekableByteChannel
。 但是返回的对象的实际类是sun.nio.ch.FileChannelImpl
(在我的Java中),因此我可以将其sun.nio.ch.FileChannelImpl
为java.nio.channels.FileChannel
并将其用作FileChannel。 有人知道Files.newByteChannel
无法返回FileChannel
的原因吗?
有人知道Files.newByteChannel无法返回FileChannel的原因吗?
FileChannel
(抽象类)实现SeekableByteChannel
接口。
通常,使用object reference of interface
而不是类始终是一种好习惯,因为如果我们更改实现,则无需在各处更改代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.