国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

Java反射框架Reflections示例詳解

瀏覽:51日期:2022-08-28 15:09:17

MAVEN 坐標

<dependency> <groupId>org.reflections</groupId> <artifactId>reflections</artifactId> <version>0.9.10</version></dependency>

Reflections 的作用

Reflections通過掃描classpath,索引元數據,并且允許在運行時查詢這些元數據。

獲取某個類型的所有子類;比如,有一個父類是TestInterface,可以獲取到TestInterface的所有子類。 獲取某個注解的所有類型/字段變量,支持注解參數匹配。 使用正則表達式獲取所有匹配的資源文件 獲取特定簽名方法。

使用Reflections可以很輕松的獲取以下元數據信息:

項目中使用:

public class ReflectionTest { public static void main(String[] args) { // 掃包 Reflections reflections = new Reflections(new ConfigurationBuilder() .forPackages('com.boothsun.reflections') // 指定路徑URL .addScanners(new SubTypesScanner()) // 添加子類掃描工具 .addScanners(new FieldAnnotationsScanner()) // 添加 屬性注解掃描工具 .addScanners(new MethodAnnotationsScanner() ) // 添加 方法注解掃描工具 .addScanners(new MethodParameterScanner() ) // 添加方法參數掃描工具 ); // 反射出子類 Set<Class<? extends ISayHello>> set = reflections.getSubTypesOf( ISayHello.class ) ; System.out.println('getSubTypesOf:' + set); // 反射出帶有指定注解的類 Set<Class<?>> ss = reflections.getTypesAnnotatedWith( MyAnnotation.class ); System.out.println('getTypesAnnotatedWith:' + ss); // 獲取帶有特定注解對應的方法 Set<Method> methods = reflections.getMethodsAnnotatedWith( MyMethodAnnotation.class ) ; System.out.println('getMethodsAnnotatedWith:' + methods); // 獲取帶有特定注解對應的字段 Set<Field> fields = reflections.getFieldsAnnotatedWith( Autowired.class ) ; System.out.println('getFieldsAnnotatedWith:' + fields); // 獲取特定參數對應的方法 Set<Method> someMethods = reflections.getMethodsMatchParams(long.class, int.class); System.out.println('getMethodsMatchParams:' + someMethods); Set<Method> voidMethods = reflections.getMethodsReturn(void.class); System.out.println( 'getMethodsReturn:' + voidMethods); Set<Method> pathParamMethods =reflections.getMethodsWithAnyParamAnnotated( PathParam.class); System.out.println('getMethodsWithAnyParamAnnotated:' + pathParamMethods); }}

具體也可以參見官方文檔:官方API

到此這篇關于Java反射框架Reflections示例詳解的文章就介紹到這了,更多相關Java反射框架Reflections內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Java
相關文章:
主站蜘蛛池模板: 美女的让男人桶到爽软件 | 亚洲第一影院 | 久草久草 | 国产亚洲精品精品国产亚洲综合 | 日本aaaa特级毛片 | 天堂成人av| 免费午夜不卡毛片 | 亚洲成人免费 | 欧美成人www在线观看网页 | 日韩乱淫 | 欧美一级欧美三级 | 香港a毛片免费全部播放 | 美女福利视频午夜在线 | 国产成人在线视频观看 | 国产成人高清精品免费软件 | 国美女福利视频午夜精品 | 性感一级毛片 | 欧美三级成版人版在线观看 | 日本三级11k影院在线 | 在线观看欧美一区 | 在线不卡一区二区 | 国产成人一区二区三区影院免费 | 亚洲性综合 | 亚洲国产精品a在线 | 亚洲国产精品综合久久 | 女人十八一级毛片 | 久久国内精品自在自线软件 | 最新亚洲人成网站在线影院 | 成年午夜一级毛片视频 | 欧美精品hdxxxxx | 国产成人精品久久一区二区三区 | 国产精品久久久久a影院 | 一区二区三区国产 | 免费国产不卡午夜福在线观看 | 国产成人精品久久二区二区 | 亚洲国产一区二区三区最新 | 精品国产91久久久久久久a | 在线免费观看欧美 | 日韩毛片 | 韩国19禁主播裸免费福利 | 欧美国产成人免费观看永久视频 |