Safe Varargs

Joe Darcy joe.darcy at oracle.com
Fri Dec 17 12:17:33 PST 2010


On 12/17/2010 12:10 PM, Bob Lee wrote:
> I'm disappointed that we're adding another type to java.lang, 
> especially for an ugly workaround. As you know, this is roughly 
> equivalent to adding a reserved word to the language.
>
> The original proposal (see below) didn't require this.
>
> I'm also not sure the new proposal addresses overriding varags 
> methods. For example, if I override a method add(T[]) with 
> add(String[]) (see proposal for more complete example), the compiler 
> should generate a warning.

As documented in its specification, the SafeVarargs annotation is only 
applicable to static methods, final instance methods, and constructors; 
therefore, overriding does not occur.  Annotation inheritance only works 
on classes (not methods, interfaces, or constructors) so without 
changing annotation inheritance, a SafeVarargs-style annotation cannot 
be passed through general instance methods in classes or through interfaces.

-Joe




More information about the coin-dev mailing list