Reputation: 136042
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
?
Upvotes: 1
Views: 671
Reputation: 16158
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.
Upvotes: 1