Javatpoint Logo
Javatpoint Logo

Java Class getDeclaredAnnotations() Method

The getDeclaredAnnotations() method of java Class class returns annotations that are directly present on this element and ignore inherited annotations. If no annotation is set, then it returns 0.

Syntax

Parameter

NA

Returns

All the annotations present on this element.

Throws

NA

Example 1

Test it Now

Output:

key: getFieldvalue
value: getting field attribute

Example 2

Test it Now

Output:

@Demointerface(str=Demo Annotation, val=100)

Java Class getDeclaredAnnotations() Method

The getDeclaredClasses() method of java Class class returns an array of the class object representing all the classes and interface declared in this class object. If no annotations are declared, then it returns an array of length 0.

Syntax

Parameter

NA

Returns

An array of class object.

Throws

No exception is thrown.

Example 1

Test it Now

Output:

Class   1 =  ClassgetDeclaredclassesExample1$InPrvtClass
Class   2 =  ClassgetDeclaredclassesExample1$InClass2
Class   3 =  ClassgetDeclaredclassesExample1$InClass1

Example 2

Test it Now

Output:

Class  1  =   AnotherClass$InnerPrivateClass
Class  2  =   AnotherClass$InrClass2
Class  3  =   AnotherClass$InrClass1

Next TopicJava Class





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA