title: Java: Convert direct ByteBuffer to double[]
body: <p>What is the best way to do that?</p>
  
  <p>I tried the following:</p>
  
  <pre><code>ByteBuffer cacheBuffer=ByteBuffer.allocateDirect(nm(nLimit,0));  //where nm(nLimit,0) is a large number
  double[] cache=cacheBuffer.asDoubleBuffer().array();
  </code></pre>
  
  <p>But I got this exception:</p>
  
  <pre><code>java.lang.UnsupportedOperationException
  at java.nio.DoubleBuffer.array(Unknown Source)
  </code></pre>
  
  <p>Why?</p>
  
  <p>Edit:</p>
  
  <p>It looks like the javadoc "Returns the double array that backs this buffer  (optional operation)." actually means array() method is simply returning the double array that is already backing this buffer. I thought it is going to convert the buffer to double[] somehow. So now it makes sense I got an exception.</p>