Got this idea from this previous question.
http://stackoverflow.com/questions/529085/java-how-to-generic-array-creation
Anyway, my code is like this:
public class Slice<E>
{
private E[] data;
public Slice(Class<E> elementType, int size)
{
//@SuppresWarnings({"unchecked"})
data = (E[])Array.newInstance(elementType, size);
}
}
I deleted the unnecessary stuff. This compiles fine when the suppress directive is commented out. When I uncomment it, I get
Error: <identifier> expected
data = (E[])Array.newInstance(elementType, size);
^
Any ideas? why would this be happening?