Why can't @SafeVarags be applied to instance methods in a final class?

巧了我就是萌 提交于 2019-12-08 16:31:21

问题


According to the documentation of SafeVarargs, the @SafeVarargs annotation can be applied only to constructors or variable arity methods that are either static or final. This is, I have read, to eliminate issues with annotation inheritance; that is to say, annotations on methods are only allowed if the method cannot be overridden. Clearly, constructors, static methods, and final methods cannot be overridden. However, neither can private methods or methods in a final class. Someone has complained about the inability to designate @SafeVarargs private methods, but neither of these issues has been addressed. In general, no one really seems to care. Am I missing something? Am I complaining about something that doesn't have any practical applications? Or... ?


回答1:


This is scheduled to be fixed in Java 9; see http://openjdk.java.net/jeps/213 .



来源:https://stackoverflow.com/questions/27208570/why-cant-safevarags-be-applied-to-instance-methods-in-a-final-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!