为什么@SafeVarags 不能应用于 final 类中的实例方法? [英] Why can't @SafeVarags be applied to instance methods in a final class?

查看:28
本文介绍了为什么@SafeVarags 不能应用于 final 类中的实例方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据文档SafeVarargs@SafeVarargs 注释只能应用于 staticfinal 的构造函数或可变参数方法.这是,我已阅读,以消除注释继承问题;也就是说,只有当方法不能被覆盖时,才允许对方法进行注释.显然,构造函数、static 方法和 final 方法不能被覆盖.但是,private 方法或 final 类 中的方法都不能.有人抱怨无法指定@SafeVarargs私有方法,但是这些问题均未得到解决.一般来说,似乎没有人真正关心.我错过了什么吗?我是在抱怨没有任何实际应用的东西吗?还是……?

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... ?

推荐答案

这计划在 Java 9 中修复;参见 http://openjdk.java.net/jeps/213.

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

这篇关于为什么@SafeVarags 不能应用于 final 类中的实例方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆