0

I am creating a deque using generic type E... Having trouble initializing some sort of generic array, while being type safe, have tried casting, however this is Type safety: Unchecked cast from Object[] to E[]

public class DequeCyclic<E> implements Deque<E> {
   private E[] line;

   public DequeCyclic(int size) {
   E[] line = (E[])new Object[size];
   }
}

Could I put in @SuppressWarnings("unchecked") to ignore the type safety issue? What is another way to create the generic deque/array?

  • Does this answer your question? [How to create a generic array in Java?](https://stackoverflow.com/questions/529085/how-to-create-a-generic-array-in-java) – tgdavies Mar 29 '23 at 13:57
  • 1
    Generally, this is done by doing a cast on the getters/dequeue method, and keeping it as an Object[]. – Louis Wasserman Mar 29 '23 at 14:50

0 Answers0