title: Casting from Object to Enum
body: <p>So I'm trying to implement a CircularBuffer in <code>Java</code>, to which I can access the underlying <code>array</code>:</p>
  
  <pre><code>/* package protected */ class CircularBuffer&lt;E&gt; {
  private final Object[] mArray;
  private int mSize;
  private int headPointer = 0;
  
  private CircularBuffer(int size) {
    mSize = size;
    mArray = new Object[mSize];
  }
  
  private void add(E elem) {
    mArray[headPointer] = elem;
    headPointer = (headPointer + 1) % mSize;
  }
  
  public E[] getArray() {
    return (E[]) this.mArray;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I want to use this with <code>Enums</code> and various primitives (specifically <code>boolean</code>s), but everything I call <code>myEnum[] = myCircularBuffer.getArray()</code>, I get a:</p>
  
  <pre><code>java.lang.ClassCastException: java.lang.Object[] cannot be cast to com.package.myEnum[]
  </code></pre>
  
  <p>Any tips on making something like this work?</p>
  
  <p>Edit: I do know about the Apache CircularFifoQueue, but I don't want to use it since its way more than I need and I'm concerned about package size. </p>