繁体   English   中英

为什么Files.newByteChannel不返回FileChannel?

[英]Why does not Files.newByteChannel return FileChannel?

java.nio.file.Files.newByteChannel返回SeekableByteChannel 但是返回的对象的实际类是sun.nio.ch.FileChannelImpl (在我的Java中),因此我可以将其sun.nio.ch.FileChannelImpljava.nio.channels.FileChannel并将其用作FileChannel。 有人知道Files.newByteChannel无法返回FileChannel的原因吗?

有人知道Files.newByteChannel无法返回FileChannel的原因吗?

FileChannel (抽象类)实现SeekableByteChannel接口。

通常,使用object reference of interface而不是类始终是一种好习惯,因为如果我们更改实现,则无需在各处更改代码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM