You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
看下RetentionPolicy的源码
public enum RetentionPolicy {
/**
* Annotations are to be discarded by the compiler.
*/
SOURCE,
注释是这样说的Annotations are to be discarded by the compiler.
意思是,SOURCE级别的注解会被compiler扔掉,也就是说编译后的代码里肯定是没有这个的。
至于@OverRide,为什么现在阿里规范里要求大家写,是因为这样在代码编译的时候,可以强制编译器去检查你的代码是不是符合Override的标准,把问题在编译期就抛出
Activity
Snailclimb commentedon Feb 21, 2019
感谢您的回答!
lanmeiniu commentedon May 31, 2019
关于抽象类
JDK 1.8以前,抽象类的方法默认访问权限为protected
JDK 1.8时,抽象类的方法默认访问权限变为default
关于接口
JDK 1.8以前,接口中的方法必须是public的
JDK 1.8时,接口中的方法可以是public的,也可以是default的
JDK 1.9时,接口中的方法可以是private的
powerLeePlus commentedon Sep 17, 2019
jdk1.8后,接口方法可以有方法体,需要用default或static修饰。实现类无需重新。当然default方法重写也是可以的。如果一个类实现多个接口,多个接口有相同default方法,则子类必须重写该方法
WangZhen-Ddm commentedon Apr 26, 2020
请问,在jdk1.8中
public class HashMap<K,V> extends AbstractMap<K,V> implements Map<K,V>, Cloneable, Serializable
HashMap继承了AbstractMap这一抽象类并实现了Map<>接口,为何其中的代码都未加@OverRide进行重写
wangpeipei90 commentedon Apr 27, 2020
@OverRide 是annotation,貌似不是必须的
chengweng commentedon Apr 27, 2020
看下@OverRide它的源码

是SOURCE级别
WangZhen-Ddm commentedon Apr 27, 2020
source级别的注解可以选择不加吗,class和runtime级别的注解是必须的吗
Amuao commentedon Oct 21, 2020
java的注解出现在Jdk1.5,而集合框架早在Jdk1.2就出现了,我觉得就是懒得加 专门去加这玩意干啥
ryuhi commentedon Oct 9, 2022
看下RetentionPolicy的源码
public enum RetentionPolicy {
/**
* Annotations are to be discarded by the compiler.
*/
SOURCE,
注释是这样说的Annotations are to be discarded by the compiler.
意思是,SOURCE级别的注解会被compiler扔掉,也就是说编译后的代码里肯定是没有这个的。
至于@OverRide,为什么现在阿里规范里要求大家写,是因为这样在代码编译的时候,可以强制编译器去检查你的代码是不是符合Override的标准,把问题在编译期就抛出