Maven: <dependency> <groupId>com.alchemy.annotations</groupId> <artifactId>alchemy-annotations</artifactId> <version>1.0.0</version> </dependency> Gradle: groovy implementation 'com.alchemy.annotations:alchemy-annotations:1.0.0' import java.lang.annotation.*; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface Author { String name(); } public class MyClass { } import java.lang.annotation.Annotation; public class Main { public static void main(String[] args) { Class<MyClass> clazz = MyClass.class; Annotation[] annotations = clazz.getAnnotations(); for (Annotation annotation : annotations) { if (annotation instanceof Author) { Author author = (Author) annotation; } } } }


上一篇:
下一篇:
切换中文