Nikem
Nikem

Reputation: 5786

rawtypes compiler warning on generic array creation

I do understand, that one cannot create array of generic class in java, e.g.

  private static final Class<String>[] ARGUMENT_TYPE = new Class<String>[]{String.class};

So I have used the raw type:

  private static final Class[] ARGUMENT_TYPE = new Class[]{String.class};

But now java compiler complains

warning: [rawtypes] found raw type: Class

private static final Class[] ARGUMENT_TYPE = new Class[]{String.class};

Is there any way aside from SuppressWarnings to say to the compiler: "shut up, I have to do this by your own specification!"

Upvotes: 4

Views: 672

Answers (1)

John Chesshir
John Chesshir

Reputation: 640

I'm not quite sure how you plan to use this static array. Some additional context would be nice.

How about this?

private static final Class<?>[] ARGUMENT_TYPE = new Class<?>[]{String.class, Int.class};

Upvotes: 2

Related Questions