Java类class isAnnotation()方法及示例
類的類isAnnotation()方法 (Class class isAnnotation() method)
isAnnotation() method is available in java.lang package.
isAnnotation()方法在java.lang包中可用。
isAnnotation() method is used to check whether this Class object represents the annotation type or not.
isAnnotation()方法用于檢查此Class對象是否表示注釋類型。
isAnnotation() 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.
isAnnotation()方法是一個非靜態方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。
isAnnotation() method does not throw an exception at the time of returning the Annotation type.
返回Annotation類型時, isAnnotation()方法不會引發異常。
Syntax:
句法:
public boolean isAnnotation();Parameter(s):
參數:
It does not accept any parameter.
它不接受任何參數。
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 this Class object denotes an annotation type.
當此Class對象表示注釋類型時,它返回true 。
It returns false, when this Class object does not denote an annotation type.
當此Class對象不表示注釋類型時,它返回false 。
Example:
例:
// Java program to demonstrate the example // of boolean isAnnotation() method of Class import java.security.*; public class NonAnnoClass {public static void main(String[] args) throws Exception {Class ann1 = Identity.class;Class ann2 = Deprecated.class;// We are checking Annotation type of Deprecated class// by using the method isAnnotation()boolean b = ann2.isAnnotation();System.out.println("Is Deprecated an Annotation type" + " " + b);// We are checking Annotation type of Identity class// by using the method isAnnotation()if (ann1.isAnnotation()) {System.out.print(ann1.getSimpleName() + "is an Annotation type.");System.out.println(ann1.isAnnotation());} else {System.out.print(ann1.getSimpleName() + " " + "is an Annotation type" + " ");System.out.println(ann1.isAnnotation());}} }Output
輸出量
Is Deprecated an Annotation type true Identity is an Annotation type false翻譯自: https://www.includehelp.com/java/class-class-isannotation-method-with-example.aspx
總結
以上是生活随笔為你收集整理的Java类class isAnnotation()方法及示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 再有人问你MySql的隔离级别,直接把这
- 下一篇: 动态规划编程面试_面试的前25大动态编程