JSR-308 and @SuppressWarnings

Alex Buckley alex.buckley at oracle.com
Mon Jun 23 21:01:08 UTC 2014


@SuppressWarnings was not changed in Java SE 8. It continues to apply to 
declarations, not types. A JEP would be needed to make @SuppressWarnings 
suitable for types inside cast expressions.

Reviewing where @SuppressWarnings appears in the JLS, another 
opportunity is to give it meaning when applied to the declaration of a 
variable arity parameter of non-reifiable type. Currently, you have the 
choice of applying @SafeVarargs to the method declaration (for certain 
kinds of method) or applying @SuppressWarnings("unchecked") to the 
method declaration (works for all kinds of method, but is a blunt tool).

Alex

On 6/23/2014 12:55 PM, Martin Buchholz wrote:
> For years, those of us maintaining low-level libraries have been writing
> code like this:
>
>                          @SuppressWarnings("unchecked") E itemE = (E) item;
>                          return itemE;
>
> hoping that JSR-308 might someday allow us to write something like:
>                         return (@SuppressWarnings("unchecked") E) item;
>
> which is clearer, more compact, and generates slightly better bytecode.
> This article:
> http://www.oracle.com/technetwork/articles/java/ma14-architect-annotations-2177655.html
> suggests that @SuppressWarnings should work "out of the box", but I
> don't see that with jdk8 javac.
>
> Are my hopes dashed?


More information about the compiler-dev mailing list