Java知识点总结(注解-内置注解)

@(Java知识点总结)[Java, 注解]

@Override

  • 定义在java.lang.Override 中,此注释只适用于修饰方法,表示一个方法声明打算重写父类的另一个方法声明。
public class Demo01 {@Overridepublic String toString() {return "";}}

源码


import java.lang.annotation.*;/*** Indicates that a method declaration is intended to override a* method declaration in a supertype. If a method is annotated with* this annotation type compilers are required to generate an error* message unless at least one of the following conditions hold:** <ul><li>* The method does override or implement a method declared in a* supertype.* </li><li>* The method has a signature that is override-equivalent to that of* any public method declared in {@linkplain Object}.* </li></ul>** @author  Peter von der Ah&eacute;* @author  Joshua Bloch* @jls 9.6.1.4 @Override* @since 1.5*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.SOURCE)
public @interface Override {
}

@Deprecated

  • 定义在java.lang.Deprecated中,遗弃、废弃,不建议使用。此注释可用于修饰方法、属性、类,表示不鼓励程序员使用这样的元素,通常是因为它很危险或存在更好的选择。
public class Demo01 {@Deprecatedpublic static void test1(){}public static void main(String[] args) {test1();}
}

源码

import java.lang.annotation.*;
import static java.lang.annotation.ElementType.*;/*** A program element annotated @Deprecated is one that programmers* are discouraged from using, typically because it is dangerous,* or because a better alternative exists.  Compilers warn when a* deprecated program element is used or overridden in non-deprecated code.** @author  Neal Gafter* @since 1.5* @jls 9.6.3.6 @Deprecated*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(value={CONSTRUCTOR, FIELD, LOCAL_VARIABLE, METHOD, PACKAGE, PARAMETER, TYPE})
public @interface Deprecated {
}

@SuppressWarings

  • 定义在java.lang.SuppressWarnings中,用来抑制编译时的警告信息。
  • 与前两个注释有所不同, 你需要添加一个参数才能正确使用 ,这些参数值是已经定义好了的,我们选择性的使用就好了,参数如下:
参数 说明
deprecation 使用了过时的类或方法的警告
unchecked 执行了未检查的转换时的警告,如使用集合时未指定泛型
fallthrough 当在switch语句使用时发生case穿透
path 在类路径、源文件路径等中有不存在路径的警告
serial 当在可序列化的类上缺少serialVersionUID定义时的警告
finally 任何finally子句不能完成时的警告
all 关于以上所有情况的警告
@SuppressWarnings("unchecked")
@SuppressWarnings(value={"unchecked","deprecation"})
import java.util.ArrayList;
import java.util.List;public class Demo01 {@SuppressWarnings("all")public static void test2(){List list = new ArrayList();}

源码

package java.lang;import java.lang.annotation.*;
import static java.lang.annotation.ElementType.*;/*** Indicates that the named compiler warnings should be suppressed in the* annotated element (and in all program elements contained in the annotated* element).  Note that the set of warnings suppressed in a given element is* a superset of the warnings suppressed in all containing elements.  For* example, if you annotate a class to suppress one warning and annotate a* method to suppress another, both warnings will be suppressed in the method.** <p>As a matter of style, programmers should always use this annotation* on the most deeply nested element where it is effective.  If you want to* suppress a warning in a particular method, you should annotate that* method rather than its class.** @author Josh Bloch* @since 1.5* @jls 4.8 Raw Types* @jls 4.12.2 Variables of Reference Type* @jls 5.1.9 Unchecked Conversion* @jls 5.5.2 Checked Casts and Unchecked Casts* @jls 9.6.3.5 @SuppressWarnings*/
@Target({TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE})
@Retention(RetentionPolicy.SOURCE)
public @interface SuppressWarnings {/*** The set of warnings that are to be suppressed by the compiler in the* annotated element.  Duplicate names are permitted.  The second and* successive occurrences of a name are ignored.  The presence of* unrecognized warning names is <i>not</i> an error: Compilers must* ignore any warning names they do not recognize.  They are, however,* free to emit a warning if an annotation contains an unrecognized* warning name.** <p> The string {@code "unchecked"} is used to suppress* unchecked warnings. Compiler vendors should document the* additional warning names they support in conjunction with this* annotation type. They are encouraged to cooperate to ensure* that the same names work across multiple compilers.* @return the set of warnings to be suppressed*/String[] value();
}

Java知识点总结(注解-内置注解)相关推荐

  1. 注解和反射详细笔记。自定义注解,元注解,内置注解。反射机制,Java Reflection,Java内存分析,反射操作注解,java.lang.reflect.Method,Class

    文章目录 注解 什么是注解 内置注解 元注解 自定义注解 反射机制 静态语言 vs 静态语言 Java Reflection 反射相关的主要API Class类 Java内存分析 创建运行时类的对象 ...

  2. java 多重注解_Java注解-元数据、注解分类、内置注解和自定义注解

    大家好,我是乐字节的小乐,上次说过了Java多态的6大特性|乐字节,接下来我们来看看Java编程里的注解. Java注解有以下几个知识点:元数据 注解的分类 内置注解 自定义注解 注解处理器 Serv ...

  3. 玩转Java注解:元注解、内置注解、自定义注解的原理和实现

    点击关注公众号,实用技术文章及时了解 来源:www.jianshu.com/p/ddd0b880641a 前言 Java 注解(Annotation)又称 Java 标注,是 JDK5.0 引入的一种 ...

  4. java 内置注解入门

    概念 注解是放在Java源码的类.方法.字段.参数前的一种特殊"注释", 注释会被编译器直接忽略,注解则可以被编译器打包进入class文件,因此,注解是一种用作标注的"元 ...

  5. 2字节取值范围_Java注解-元数据、注解分类、内置注解和自定义注解|乐字节

    大家好,我是乐字节的小乐,上次说过了Java多态的6大特性|乐字节,接下来我们来看看Java编程里的注解. Java注解有以下几个知识点: 元数据 注解的分类 内置注解 自定义注解 注解处理器 Ser ...

  6. 模拟hibernate的注解来创建数据表,内置注解

    目录 导读 注解释义 注解定义 内置三大注解 override注解 Deprecated注解 SuppressWarnings注解 元注解 SOURCE和RUNTIME的区别 SOURCE RUNTI ...

  7. 我的世界java版使用剑_我的世界:JAVA版藏“私货”内置绝世好剑与神功,你玩的版本有吗...

    导语:我的世界:JAVA版藏"私货"内置绝世好剑与神功,你玩的版本有吗! 在我的世界这款游戏中,每件物品都有它自己存在的作用,铁镐挖矿,盔甲防护,却也有一些物品被创作者赋予了奇怪的 ...

  8. 企业级JAVA快速开发平台, 内置代码生成器 - JavaFast快速开发平台

    企业级JAVA快速开发平台, 内置代码生成器 - JavaFast快速开发平台 JavaFast是一款基于代码生成器的智能快速开发平台,可以帮助解决java项目中80%的重复工作,让开发者更多关注业务 ...

  9. JavaFast技术特点介绍-企业级JAVA快速开发平台, 内置java代码生成器

    企业级JAVA快速开发平台, 内置代码生成器 - JavaFast快速开发平台 JavaFast是一款基于代码生成器的智能快速开发平台,可以帮助解决java项目中80%的重复工作,让开发者更多关注业务 ...

最新文章

  1. Repository 设计模式介绍
  2. kafka重新启动时出现:found a corrupted index file due to requirement failed问题解决方法
  3. mybatis基于注解的入门案例
  4. 操作系统基本分段存储管理方式
  5. 阿里雷卷:Reactive 基金会的成立将对开发方式带来哪些影响?
  6. 第二百一十七节,jQuery EasyUI,NumberSpinner(数字微调)组件
  7. 创作一个数字人,总共分几步?(下)
  8. 常见电脑字符编码总结
  9. 助力全站WebP ,阿里云云上FPGA 团队发布 WebP图片解决方案
  10. python版本切换_电脑上安装两个版本的python时,迅速切换环境
  11. Java学习基础(三):Eclispe的简单安装及使用
  12. UIControl IOS控件编程—IOS开发
  13. 回调函数Callback
  14. 计算机长宽高公式,单位换算公式大集合
  15. Bugku CTF 每日一题 想蹭网先解开密码
  16. java如何设置直线的宽度_设置线条的宽度lineWidth
  17. ActiveMq NON_PERSISTENT与PERSISTENT以及 durable subscription(持久订阅)的理解
  18. 为什么要读“无用”的古文
  19. 闪马智能+兑观科技|视频智能解析联合实验室揭牌成立
  20. 读书之乐 摘自《致青年朋友》

热门文章

  1. 暑假集训-个人赛第六场
  2. 【计算几何】点在多边形内部
  3. 推荐系统相关资源搜集
  4. delphi函数,识别字符集编码
  5. 计算机主机信息怎么看,本机电脑硬件配置信息怎么看?Win7/Win10查看详细电脑配置方法...
  6. oracle单表存储记录,oracle从各个表获得数据保存到另一个表
  7. 同一个浏览器打开不同端口的程序登录_【BI报表制作】单点登录与个性化开发...
  8. discuz设置用户每天回帖数_discuz回贴通知插件实现-显示用户状态设置
  9. redis 缓存 @class: 会有 $hibernateproxy_微信亿级在线点赞系统,用Redis如何实现?
  10. 闪退没由报错_关于floor()报错注入,你真的懂了吗?