简体   繁体   中英

Why does not Files.newByteChannel return FileChannel?

java.nio.file.Files.newByteChannel returns SeekableByteChannel . But actual class of the object returned is sun.nio.ch.FileChannelImpl (in my Java) so I can cast it to java.nio.channels.FileChannel and use it as a FileChannel. Does anybody know the reason why Files.newByteChannel cannot return FileChannel ?

Does anybody know the reason why Files.newByteChannel cannot return FileChannel?

FileChannel (abstract class) implements SeekableByteChannel interface.

Generally it is always good practice to use object reference of interface instead of class because if we change the implementation then we do not need to change the code everywhere.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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