0

Can you help me how to fix the size ​​in the below code? I tried using the usual methods with Object


public class DequeCyclic<E>{
    E[] queue;
    public DequeCyclic(int size) {
      DequeCyclic<E> queue = new DequeCyclic<E>(size);
    }
}

and queue = new E[size]

but it didn't work

HariHaravelan
  • 1,041
  • 1
  • 10
  • 19
  • 2
    This should lead to infinite object creation since you're calling the constructor inside constructor – HariHaravelan Mar 30 '22 at 12:03
  • You cannot create an array of a generic type in Java, because of type erasure. Arrays and generics don't play nice together. Possible solution: Make the member `queue` something else than an array; make it a `List` instead, for example. – Jesper Mar 30 '22 at 12:25
  • I use generic array 'queue = (E[]) new Object[size]; ' then it said Note: __tester__.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. – Chi Anh Truon Mar 30 '22 at 13:57

0 Answers0