Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't the annotation @SafeVarargs be applied to non-final instance methods?

Why can't the annotation @SafeVarargs be applied to non-final instance methods?

like image 780
Kumar Abhinav Avatar asked Jul 28 '14 12:07

Kumar Abhinav


1 Answers

If you declare @SafeVarargs, then you must be sure it is actually safe. If a method is non-final, it can be overridden in a subclass. That override might not be safe.

By requiring that the method is final, the developer can guarantee that the declaration he made (namely that its varargs use is safe) is actually always true (provided of course that the developer actually provided a safe varargs method), and that it wasn't actually broken by a subclass incorrectly reimplementing the method.

like image 143
Mark Rotteveel Avatar answered Oct 24 '22 16:10

Mark Rotteveel