Re: array of lists



Wesley Hall wrote:
Thomas Hawtin wrote:

@SuppressWarnings({"unchecked"})
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.

Yes, creating an array with a generic type is BAD. Ditch the 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.

But there is no need to let these creep into your code.

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.

In Java, a warning is essentially an error that cannot be treated as such due to backward compatibility concerns. If you blindly suppress notifications of errors, then you are storing up problems for future developers. Even if no problem is (thought to be) posed, it is far better to fix the cause rather than the effect.

Tom Hawtin
.