0
class car<T>{ 
    car<T>[] name;
    name=(car<T>[]) new Object[5];

}

I tried to create an array of the class but the declare seem wrong. how should I set length of the array to 5 here?

Giorgi Tsiklauri
  • 9,715
  • 8
  • 45
  • 66
Tyler Lg
  • 3
  • 3

1 Answers1

1

Use java.lang.reflect.Array#newInstance:

car<T>[] name = (car<T>[]) java.lang.reflect.Array.newInstance(car.class, 5);
Unmitigated
  • 76,500
  • 11
  • 62
  • 80