Without any type annotations:
package com.logicbig.example.clazz;
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedType;
import java.lang.reflect.Type;
import java.util.Arrays;
public class GetAnnotatedInterfacesExample {
public static void main(String... args) {
for (AnnotatedType annotatedType : MyClass.class.getAnnotatedInterfaces()) {
Type type = annotatedType.getType();
System.out.println("Type :" + type);
Annotation[] annotations = annotatedType.getAnnotations();
System.out.println(Arrays.toString(annotations));
Annotation[] declaredAnnotations = annotatedType.getDeclaredAnnotations();
System.out.println(Arrays.toString(declaredAnnotations));
}
}
private static class MyClass implements Serializable {
}
}
Output
Type :interface java.io.Serializable
[]
[]
With a type annotation:
package com.logicbig.example.clazz;
import java.io.Serializable;
import java.lang.annotation.*;
import java.lang.reflect.AnnotatedType;
import java.lang.reflect.Type;
import java.util.Arrays;
public class GetAnnotatedInterfacesExample2 {
public static void main(String... args) {
AnnotatedType[] ais = MyClass.class.getAnnotatedInterfaces();
for (AnnotatedType annotatedType : ais) {
Type type = annotatedType.getType();
System.out.println("Type :" + type);
System.out.println("-- type annotations --");
Annotation[] annotations = annotatedType.getAnnotations();
System.out.println(Arrays.toString(annotations));
Annotation[] declaredAnnotations = annotatedType.getDeclaredAnnotations();
System.out.println(Arrays.toString(declaredAnnotations));
}
}
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE_USE})
private @interface FileSystem {
}
private static class MyClass implements @FileSystem Serializable {
}
}
Output
Type :interface java.io.Serializable
-- type annotations --
[@com.logicbig.example.clazz.GetAnnotatedInterfacesExample2$FileSystem()]
[@com.logicbig.example.clazz.GetAnnotatedInterfacesExample2$FileSystem()]