0

I have a following array:

public static Class[] GLOBAL_FEATURE_EXTRACTORS = {
            CEDD.class,
            AutoColorCorrelogram.class
}

and right now I have a following warning:

Class is a raw type. References to generic type Class<T> should be parameterized

Both CEDD and AutoColorCorrelogram classes implements GlobalFeature interface

How to correctly parameterize Class[] in order to avoid this warning ?

alexanoid
  • 24,051
  • 54
  • 210
  • 410
  • use `Class[]`? But I suggest you use a List or a Set –  Jul 06 '16 at 16:46
  • Class[] GLOBAL_FEATURE_EXTRACTORS - fails with a following compilation error: Cannot create a generic array of Class – alexanoid Jul 06 '16 at 16:48
  • 1
    @RC. I don't think that'd work. Probably something like `Class>[]`... – assylias Jul 06 '16 at 16:48
  • Generic arrays aren't supported in java: https://docs.oracle.com/javase/tutorial/java/generics/restrictions.html#createArrays – EpicPandaForce Jul 06 '16 at 16:49
  • I usually use guava ImmutableList.of() for this kind of constants, so not sure about arrays. Should this be closed as a duplicate of http://stackoverflow.com/questions/16952283/raw-type-references-to-generic-types-should-be-parameterized?rq=1 ? –  Jul 06 '16 at 16:50
  • 2
    Class>[] works fine, thanks. – alexanoid Jul 06 '16 at 16:51
  • 1
    I recommend using a collection, which can be typed, eg `public static List> FOO = Arrays.asList(Integer.class, Long.class);` – Bohemian Jul 06 '16 at 17:01

0 Answers0