1.class public LMain; 2.super Ljava/lang/Object; 3 4 5#expected output: 6#@ClassAnnotation() 7#@MethodAnnotation() 8#@FieldAnnotation() 9#@ParameterAnnotation() 10 11 12.method public static main([Ljava/lang/String;)V 13 .registers 1 14 15 invoke-static {}, LMain;->testClassAnnotation()V 16 17 invoke-static {}, LMain;->testMethodAnnotation()V 18 19 invoke-static {}, LMain;->testFieldAnnotation()V 20 21 const-string v0, "" 22 23 invoke-static {v0}, LMain;->testParameterAnnotation(Ljava/lang/String;)V 24 25 return-void 26.end method 27 28.annotation runtime LClassAnnotation; 29.end annotation 30 31.method public static testClassAnnotation()V 32 .registers 3 33 34 sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream; 35 36 const-class v1, LMain; 37 const-class v2, LClassAnnotation; 38 39 invoke-virtual {v1, v2}, Ljava/lang/Class;->getAnnotation(Ljava/lang/Class;)Ljava/lang/annotation/Annotation; 40 move-result-object v1 41 42 invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/Object;)V 43 44 return-void 45.end method 46 47 48 49.method public static testMethodAnnotation()V 50 .registers 4 51 52 .annotation runtime LMethodAnnotation; 53 .end annotation 54 55 sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream; 56 57 const-class v1, LMain; 58 const-string v2, "testMethodAnnotation" 59 60 const/4 v3, 0 61 new-array v3, v3, [Ljava/lang/Class; 62 63 invoke-virtual {v1, v2, v3}, Ljava/lang/Class;->getMethod(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method; 64 move-result-object v1 65 66 const-class v2, LMethodAnnotation; 67 68 invoke-virtual {v1, v2}, Ljava/lang/reflect/Method;->getAnnotation(Ljava/lang/Class;)Ljava/lang/annotation/Annotation; 69 move-result-object v1 70 71 invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/Object;)V 72 73 return-void 74.end method 75 76 77.field public static fieldAnnotationTest:Ljava/lang/Object; 78 .annotation runtime LFieldAnnotation; 79 .end annotation 80.end field 81 82.method public static testFieldAnnotation()V 83 .registers 3 84 85 sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream; 86 87 const-class v1, LMain; 88 const-string v2, "fieldAnnotationTest" 89 90 invoke-virtual {v1, v2}, Ljava/lang/Class;->getField(Ljava/lang/String;)Ljava/lang/reflect/Field; 91 move-result-object v1 92 93 const-class v2, LFieldAnnotation; 94 95 invoke-virtual {v1, v2}, Ljava/lang/reflect/Field;->getAnnotation(Ljava/lang/Class;)Ljava/lang/annotation/Annotation; 96 move-result-object v1 97 98 invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/Object;)V 99 100 return-void 101.end method 102 103 104.method public static testParameterAnnotation(Ljava/lang/String;)V 105 .registers 6 106 107 .param p0 # Ljava/lang/String; 108 .annotation runtime LParameterAnnotation; 109 .end annotation 110 .end param 111 112 113 sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream; 114 115 const-class v1, LMain; 116 const-string v2, "testParameterAnnotation" 117 118 const/4 v3, 1 119 new-array v3, v3, [Ljava/lang/Class; 120 121 const-class v4, Ljava/lang/String; 122 const/4 v5, 0 123 aput-object v4, v3, v5 124 125 invoke-virtual {v1, v2, v3}, Ljava/lang/Class;->getMethod(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method; 126 move-result-object v1 127 128 129 invoke-virtual {v1}, Ljava/lang/reflect/Method;->getParameterAnnotations()[[Ljava/lang/annotation/Annotation; 130 move-result-object v1 131 132 aget-object v1, v1, v5 133 aget-object v1, v1, v5 134 135 invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/Object;)V 136 137 return-void 138.end method