Re: array of lists
- From: Wesley Hall <noreply@xxxxxxxxxxx>
- Date: Sun, 10 Dec 2006 15:53:29 +0000
Thomas Hawtin wrote:
Wesley Hall wrote:
Seems there is lots of discussion on the creation of generic arrays in
Java, but the bottom line seems to be that you cant do it in any
Just don't use them. With generics there is little use for arrays of
reference types. Just use a List.
If you just want to clear the compiler warning, put the following
annotation on the method that does the add..
That is a measure of last resort. Not something to be thrown around just
to make the compiler shut up. If the compiler is making a noise, there
is probably a good reason.
In this case, it seems to be that the compiler is moaning that the OP is
using an array with no generic type, but as there seems to be no way to
create an array WITH a generic type (no reasonable way at least) then it
is not possible to avoid the compiler warning and still use arrays.
Using a list (as per you first point) is a reasonable measure but is not
always an option. There is still plenty of third party code that
requires the use of reference type arrays.
I don't agree that the above annotation is 'the measure of a last
resort'. A warning is exactly that, a warning. Once the developer has
analysed the problem, determining that the warning is valid but doesn't
pose any problem then using the annotation to suppress the warning is a
good move. It will prevent the next developer to compile the code from
wasting time analysing a superfluous warning.
- Prev by Date: importing package
- Next by Date: Re: importing package
- Previous by thread: Re: array of lists
- Next by thread: Re: array of lists