简体   繁体   中英

Creating an array of concrete instances of a generic class

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.

使用原始类型创建数组:

Position<String>[] suitPositions = new Position[5];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM