• Post Reply Bookmark Topic Watch Topic
  • New Topic

question about API info on Sun's website  RSS feed

 
Joy DeGrazzio
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://java.sun.com/j2se/1.4.2/docs/api/index.html
Most of the methods for File Channels and ByteBuffers are listed as abstract, but seem to be implemented. I find this confusing. Does anyone know what I mean? For example, the getInt() method for ByteBuffer is listed as abstract, but I've tried that method in my test program, and it works. Am I missing something or is the documentation just wrong?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that you don't create ByteBuffers using a constructor; you get them from the static allocate() and wrap() methods. The objects returned by these methods are not instances of ByteBuffer itself, but instances of subclasses of ByteBuffer. The same is true of virtually all of the other java.nio classes. ByteBuffer has abstract methods, but the subclasses actually implement those methods.
Methods like allocate() and wrap() are called abstract factory methods; they allow your code to work with one generic class interface while actually making use of different implementation classes for different situations.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!