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?
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).If you use Helios, you will need to set a specific option to allow
@SuppressWarnings("unchecked")
instead of@SuppressWarnings("rawtypes")
,Resources :
EDIT: Here is the now unavailable knol article that was used as a reference, originally written by Alex Miller.
Note that Eclipse 3.5 doesnt understand rawtypes and flags a warning to switch to unchecked. It is frustrating that Eclipse came up with rawtypes annotation which causes more problems than solving. They should have just stuck with the standard one.