1

I have a generic class Position<E> and a concrete class Card. How do I create an array of type Position<Card>?

I tried: Position<Card>[] suitPositions = (Position<Card>[]) new Object[5];
but I get a ClassCastException.

But when I try: Position<String>[] suitPositions = (Position<String>[]) new Object[5];
it works just fine.

1 Answers1

1

Use the raw type to create the array:

Position<String>[] suitPositions = new Position[5];
fabian
  • 67,623
  • 12
  • 74
  • 102