av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

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

Java反射框架Reflections示例詳解

瀏覽:60日期: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通過(guò)掃描classpath,索引元數(shù)據(jù),并且允許在運(yùn)行時(shí)查詢(xún)這些元數(shù)據(jù)。

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

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

項(xiàng)目中使用:

public class ReflectionTest { public static void main(String[] args) { // 掃包 Reflections reflections = new Reflections(new ConfigurationBuilder() .forPackages('com.boothsun.reflections') // 指定路徑URL .addScanners(new SubTypesScanner()) // 添加子類(lèi)掃描工具 .addScanners(new FieldAnnotationsScanner()) // 添加 屬性注解掃描工具 .addScanners(new MethodAnnotationsScanner() ) // 添加 方法注解掃描工具 .addScanners(new MethodParameterScanner() ) // 添加方法參數(shù)掃描工具 ); // 反射出子類(lèi) Set<Class<? extends ISayHello>> set = reflections.getSubTypesOf( ISayHello.class ) ; System.out.println('getSubTypesOf:' + set); // 反射出帶有指定注解的類(lèi) Set<Class<?>> ss = reflections.getTypesAnnotatedWith( MyAnnotation.class ); System.out.println('getTypesAnnotatedWith:' + ss); // 獲取帶有特定注解對(duì)應(yīng)的方法 Set<Method> methods = reflections.getMethodsAnnotatedWith( MyMethodAnnotation.class ) ; System.out.println('getMethodsAnnotatedWith:' + methods); // 獲取帶有特定注解對(duì)應(yīng)的字段 Set<Field> fields = reflections.getFieldsAnnotatedWith( Autowired.class ) ; System.out.println('getFieldsAnnotatedWith:' + fields); // 獲取特定參數(shù)對(duì)應(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); }}

具體也可以參見(jiàn)官方文檔:官方API

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

標(biāo)簽: Java
相關(guān)文章:
主站蜘蛛池模板: 亚洲精品白浆高清久久久久久 | 国产精品久久国产精品 | 精品久久不卡 | 国产精品久久久久久亚洲调教 | 日韩中文字幕视频 | 亚洲国产精品一区二区久久 | 在线观看的av | 亚洲精品免费观看 | 中文字幕a√| 日韩高清黄色 | 国产成人精品区一区二区不卡 | 国产一区不卡 | 国产精品精品久久久久久 | 欧美成人免费在线 | 午夜影院在线观看免费 | 国产欧美精品一区二区 | 免费精品| 北条麻妃av一区二区三区 | 91在线观看免费 | 国产精品一区在线观看 | 日韩视频―中文字幕 | 欧美成ee人免费视频 | 免费一级淫片aaa片毛片a级 | 免费国产一区二区 | 美女一区 | 国产精品久久久久久久久久 | 美女国产精品 | 国产精品国产a级 | 黑人精品xxx一区一二区 | 欧美三级免费观看 | 91麻豆精品国产91久久久久久 | 在线播放91 | 久久久久久综合 | 在线一区二区三区 | 午夜精品一区二区三区三上悠亚 | 中文字幕高清在线 | 亚洲高清在线观看 | 黄色一级特级片 | 欧美日韩国产精品激情在线播放 | 亚洲欧美中文日韩在线v日本 | av国产精品 |