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?
java.nio.file.Files.newByteChannel returns SeekableByteChannel . But actual class of the object returned is sun.nio.ch.FileChannelImpl (in
Share
FileChannel(abstract class) implementsSeekableByteChannelinterface.Generally it is always good practice to use
object reference of interfaceinstead of class because if we change the implementation then we do not need to change the code everywhere.