[英]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.