JDK-5082736 : Subclasses of java.nio.Buffer should use covariant return types
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 5.0
  • Priority: P5
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-08-04
  • Updated: 2017-05-11
  • Resolved: 2004-08-04
Related Reports
Duplicate :  
Relates :  
Description

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) 
======================================================================