Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-5082736

Subclasses of java.nio.Buffer should use covariant return types

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P5 P5
    • None
    • 5.0
    • core-libs
    • x86
    • windows_xp



      Name: jl125535 Date: 08/04/2004


      A DESCRIPTION OF THE REQUEST :
      java.nio.Buffer subclasses should support covariant return types for methods mark(), limit(int), position(int)...


      JUSTIFICATION :
      These methods return 'this', so multiple statements can be put in one line. Therefore the reference returned should be a subclass of Buffer so that methods specific to the subclass can be called on the same line.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      ByteBuffer should return a ByteBuffer when calling methods mark(), clear(), flip()...
      ACTUAL -
      ByteBuffer.mark() returns a Buffer reference.

      ---------- BEGIN SOURCE ----------
      import java.nio.*;
      public class BufferRFE {

      public static void main(String[] args) {
      ByteBuffer buffer = ByteBuffer.allocate(1024);
      buffer.mark().put(new byte[1024]).rewind();// compile-time error Method put() not found in class Buffer
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      buffer.mark();
      buffer.put(new byte[1024]);
      buffer.rewind();
      (Incident Review ID: 295628)
      ======================================================================

            mr Mark Reinhold
            jleesunw Jon Lee (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: