Quantcast
Channel: How can I create a generic array in Java? - Stack Overflow
Viewing all articles
Browse latest Browse all 66

Answer by Jeff Olson for How can I create a generic array in Java?

$
0
0

This is covered in Chapter 5 (Generics) of Effective Java, 2nd Edition, item 25...Prefer lists to arrays

Your code will work, although it will generate an unchecked warning (which you could suppress with the following annotation:

@SuppressWarnings({"unchecked"})

However, it would probably be better to use a List instead of an Array.

There's an interesting discussion of this bug/feature on the OpenJDK project site.


Viewing all articles
Browse latest Browse all 66

Trending Articles