Suppressed Warnings

1 view
Skip to first unread message

Will

unread,
Nov 29, 2010, 10:37:55 PM11/29/10
to Cornell CS 2110
I found it useful to create a queue data structure that stores a fixed
number of elements and automatically removes the oldest element when
you try to add a new element. I'm just using a basic array to store
the elements.

However, apparently in Java you can't create an array of generics, so
trying the code
T[] elements = new T[maxSize];
gives an error.

I can get around this by doing T[] elements = (T[]) new
Object[maxSize];

However, I then get a warning from Eclipse about unchecked casting. Is
it ok to just ignore this error and add a
@SuppressWarnings("unchecked")

at the top of the class definition, or is this a bad idea?

Lonnie Princehouse

unread,
Nov 29, 2010, 10:47:21 PM11/29/10
to cornell...@googlegroups.com
You could suppress the warnings, but it would be better to use an ArrayList.


--
You received this message because you are subscribed to the Google Groups "Cornell CS 2110" group.
To post to this group, send email to cornell...@googlegroups.com.
To unsubscribe from this group, send email to cornell-cs211...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cornell-cs2110?hl=en.


Reply all
Reply to author
Forward
0 new messages