亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術(shù)文章
文章詳情頁

Java反射框架Reflections示例詳解

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

MAVEN 坐標(biāo)

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

Reflections 的作用

Reflections通過掃描classpath,索引元數(shù)據(jù),并且允許在運(yùn)行時查詢這些元數(shù)據(jù)。

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

使用Reflections可以很輕松的獲取以下元數(shù)據(jù)信息:

項目中使用:

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() ) // 添加方法參數(shù)掃描工具 ); // 反射出子類 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); // 獲取帶有特定注解對應(yīng)的方法 Set<Method> methods = reflections.getMethodsAnnotatedWith( MyMethodAnnotation.class ) ; System.out.println('getMethodsAnnotatedWith:' + methods); // 獲取帶有特定注解對應(yīng)的字段 Set<Field> fields = reflections.getFieldsAnnotatedWith( Autowired.class ) ; System.out.println('getFieldsAnnotatedWith:' + fields); // 獲取特定參數(shù)對應(yīng)的方法 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

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

標(biāo)簽: Java
相關(guān)文章:
主站蜘蛛池模板: 99视频在线观看视频一区 | 我想看一级黄色大片 | 成人在线短视频 | 国产精品88 | 黄色仓库在线观看 | 91短视频在线看 | 青青青青啪视频在线观看 | 黄色在线视频免费看 | 免费黄色小视频 | 99精品国产一区二区三区 | 大学生一级毛片高清版 | 中文字幕日韩一区二区 | 日本一级www | 高清不卡一区二区 | 在线视频一二三区 | 免费在线观看色 | 爱婷婷网站在线观看 | a毛片免费全部在线播放毛 a毛片免费全部播放毛 | 91青青青青青爽在线 | 久久这里只有精品免费播放 | 大学生a级毛片免费观看 | 亚洲伊人精品综合在合线 | 毛片视频免费 | 亚洲无色 | 成人亚洲网站 | 在线观看黄日本高清视频 | 亚洲第九十九页 | 国产成人h片视频在线观看 国产成人lu在线视频 | 亚洲综合图色国模40p | 日韩色影视| 女人aaaaa片一级一毛片 | 欧美3p在线观看一区二区三区 | 在线欧美一区 | 国产精品高清一区二区 | 日本免费不卡一区二区 | 国产色婷婷免费视频 | 中国性视频 | 国外成人免费高清激情视频 | aaa级精品久久久国产片 | 碰超在线| 欧美一区永久视频免费观看 |