类类isAnnotationPresent()方法 (Class class isAnnotationPresent() method)

  • isAnnotationPresent() method is available in java.lang package.

    isAnnotationPresent()方法在java.lang包中可用。

  • isAnnotationPresent() method returns true when the annotation for the given type exists on this entity otherwise it returns false.

    当给定类型的注释存在于此实体上时, isAnnotationPresent()方法将返回true,否则将返回false。

  • isAnnotationPresent() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    isAnnotationPresent()方法是一个非静态方法,仅可通过类对象访问,如果尝试使用类名访问该方法,则会收到错误消息。

  • isAnnotationPresent() method: may throw an exception at the time checking present annotation.

    isAnnotationPresent()方法 :在检查当前注释时可能会引发异常。

    NullPointerException: In this exception, when the given annotation class is null.

    NullPointerException :在此异常中,当给定的注释类为null时。

Syntax:

句法:

    public boolean isAnnotationPresent(Class ann_class);

Parameter(s):

参数:

  • Class ann_class – represents the Class object similar or correspondent to the annotation type.

    类ann_class –表示与注释类型相似或对应的Class对象。

Return value:

返回值:

The return type of this method is boolean, it returns a boolean value based on the following cases,

此方法的返回类型为boolean ,它基于以下情况返回布尔值:

  • It returns true, when an annotation for the given type exists on this entity.

    当给定类型的注释存在于此实体上时,它返回true

  • It returns false, when an annotation for the given type does not exists.

    当给定类型的注释不存在时,它返回false

Example:

例:

// Java program to demonstrate the example
// of boolean isAnnotationPresent(Class ann_class) method of Class
import java.security.*;
public class IsAnnotationPresentOfClass {public static void main(String[] args) throws Exception {Class ann1 = Identity.class;
Class ann2 = Deprecated.class;
// We are checking Annotation Present type of Deprecated
//class by using the method isAnnotationPresent()
boolean b1 = ann2.isAnnotationPresent(ann2);
System.out.println("is Deprecated an Annotation Present type" + " " + b1);
// We are checking Annotation Present type of Identity class
// by using the method isAnnotationPresent()
boolean b2 = ann1.isAnnotationPresent(ann1);
System.out.println("is Deprecated an Annotation Present type" + " " + b2);
}
}

Output

输出量

is Deprecated an Annotation Present type false
is Deprecated an Annotation Present type false

翻译自: https://www.includehelp.com/java/class-class-isannotationpresent-method-with-example.aspx

Java类class isAnnotationPresent()方法与示例相关推荐

  1. java.util.zip 用法,Java压缩文件工具类ZipUtil使用方法代码示例

    本文实例通过Java的Zip输入输出流实现压缩和解压文件,前一部分代码实现获取文件路径,压缩文件名的更改等,具体如下: package com.utility.zip; import java.io. ...

  2. java 编写方法和属性,Java类属性及方法的定义

    文章导读 [在定义类时,经常需要抽象出它的属性和方法,并定义在类的主体中.本文探讨Java类属性及方法的定义和使用.通过本文的学习,你将了解如何在Java类中定义属性及方法.属性值的设置和获取.] 本 ...

  3. thymeleaf 调用java,thymeleaf模板引擎调用java类中的方法(附源码)

    前言 由于开源了项目的缘故,很多使用了My Blog项目的朋友遇到问题也都会联系我去解决,有的是把问题留在项目的issue里提出,有的是在我的私人博客里留言,还有的则是直接添加我的qq来找我讲自己遇到 ...

  4. java散列法的运用实例,Java HashMap compute() 使用方法及示例

    Java HashMap compute() 使用方法及示例 Java HashMap compute()方法计算一个新值,并将其与哈希映射中的指定键相关联. compute()方法的语法为: has ...

  5. JSP中调用java类中的方法

    JSP中调用java类中的方法 1.新建一个项目,在src文件夹下添加一个包:如:test 2.再在包中添加一个类:如 package test; public class conDatabase { ...

  6. math的用法在java中的使用,Java Math cbrt() 使用方法及示例

    Java Math cbrt() 使用方法及示例 Java Math cbrt()方法返回指定数字的立方根. cbrt()方法的语法为: Math.cbrt(double num) 注意:cbrt() ...

  7. java arraylist 方法返回值,Java ArrayList get() 使用方法及示例

    Java ArrayList get() 使用方法及示例 Java ArrayList get()方法返回指定位置存在的元素. get()方法的语法为: arraylist.get(int index ...

  8. java kryo_Kryo框架使用方法代码示例

    Kryo框架的source已移至https://github.com/EsotericSoftware/kryo ,进入此页面,然后点击右边的Download Zip按钮,就能下载到最新版本的Kryo ...

  9. java readtimeout_Java HttpURLConnection.getReadTimeout方法代码示例

    import java.net.HttpURLConnection; //导入方法依赖的package包/类 /** * 得到响应对象 * * @param urlConnection * @retu ...

最新文章

  1. Redis进阶实战用法深剖析
  2. gulp将多张小图自动合成雪碧图
  3. python中ocr软件tesseract使用
  4. Altium Designer将Gerber转换为PCB文件教程
  5. java mongo api_MONGODB的javaAPI简单应用
  6. [Android]Thread线程入门3--多线程
  7. php 如何让html表单当中的数据在修改mysql的时候自动变更_怎么用php把html表单内容写入数据库?...
  8. 大数据面试-05-大数据工程师面试题
  9. C语言之数组探究(一):定义、大小、初始化、访问和三要素
  10. 智能一代云平台(三):15年上半年维护总结
  11. 数学建模算法与应用学习blog
  12. CANOPEN 学习(一) CANFestival 字典工具 环境搭建
  13. 轴承行业PLM解决方案
  14. java 系统找不到路径_java IOException:系统找不到指定的路径
  15. OpenStack in containers
  16. 解决Win10无法安装.Net Framework 3.5,错误代码0x800F081F
  17. qt websocket android,QT使用websocket进行长连接
  18. varnish php,php监控varnish状态
  19. c语言单片机温度调节系统设计,基于单片机的温度控制器系统总体设计方案
  20. px4机架和混控文件读取

热门文章

  1. java plug机制_插件机制 - OpooPress - 基于 Java 的静态博客生成器
  2. android app应用后台休眠,安卓手机锁屏后程序自动关闭,怎么设置手机app允许锁屏后台运行...
  3. php进程通讯方式,PHP进程模型、进程通讯方式、进程线程的区别分别有哪些?
  4. 传百度无人车计划分拆,百度回复:不实信息,目前未有分拆计划
  5. 客户端SDK测试思路
  6. Vue+axios统一接口管理
  7. 15.2. important
  8. [Array]Majority Element
  9. Android 照相功能
  10. mysql decode语句_MySQL复制问题的分析