user1063042
user1063042

Reputation: 283

Obtaining Class<T[]> without creating an array

Given a Class<T> is there any way to get a Class<T[]> without first creating an array via Array.newInstance? Even that doesn't really do quite what I want because Array.newInstance would return something of type Object, so I'd still be left doing an unchecked cast.

Upvotes: 0

Views: 80

Answers (1)

Rob I
Rob I

Reputation: 5737

Use Class.forName():

Class<?> arrayofTsClass = Class.forName("[L" + tClass.getName() + ";");

Upvotes: 2

Related Questions