public class GetDeclaredAnnotationsByTypeExample {
private static class Test { @Deprecated @ReadOnly private String str; }
public static void main(String... args) throws NoSuchFieldException { Field f = Test.class.getDeclaredField("str"); ReadOnly[] a = f.getDeclaredAnnotationsByType(ReadOnly.class); System.out.println(a.length); Arrays.stream(a).forEach(System.out::println); }