簡體   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