views:

480

answers:

1

I moved to a new machine which has the latest Sun's Java compiler and noticed some warnings in the existing Java 6 code. The Eclipse IDE, suggested that I annotate the assignment with:

@SuppressWarnings("rawtypes")

For example:

class Foo<T> {
...
}
...
@SuppressWarnings("rawtypes")
Foo foo = new Foo();

When I moved back to the machine with the older compiler (JDK 1.6.0_20), I have noticed that this older compiler now warns about the suppression of "rawtypes" warnings, claiming that this suppression is unsupported and proposing to replace it with @SuppressWarnings("unchecked"). Also, there were some places which the newest compiler, by default, made me to put both "unchecked" and "rawtypes" - compiling that code with the older compiler reproduces the same warning.

How can I enforce backward/forward compatibility between the two, so that neither compiler produces warnings?

+5  A: 

You can use the @SuppressWarnings("unchecked") which is supported by both the eclipse compiler and javac.

But remember the @SuppressWarnings annotation is used by your compiler which can have its own values. The JLS only forces the compiler to understand the values "unchecked" and "deprecated" (for now).

Compiler vendors should document the warning names they support in conjunction with this annotation type. They are encouraged to cooperate to ensure that the same names work across multiple compilers.

If you use Helios, you will need to set a specific option to allow @SuppressWarnings("unchecked") instead of @SuppressWarnings("rawtypes"),

In case it is not possible to update the code with the new token, the suppressRawWhenUnchecked=true system property can be set when starting Eclipse.


Resources :

Colin Hebert
The eclipse compiler in helios rejects `@SuppressWarnings("unchecked")` and suggests what leden said.
Willi
@Willi, You're right, I updated my post with more informations for helios.
Colin Hebert