java反射初探
作者:互联网
1.比较好用的一个反射库-Reflections
// 获取某个包下类型注解对应的类
Set<Class<?>> typeClass = reflections.getTypesAnnotatedWith(RpcInterface.class, true);
// 获取子类
Set<Class<? extends SomeType>> subTypes = reflections.getSubTypesOf(SomeType.class);
// 获取注解对应的方法
Set<Method> resources =reflections.getMethodsAnnotatedWith(SomeAnnotation.class);
// 获取注解对应的字段
Set<Field> ids = reflections.getFieldsAnnotatedWith(javax.persistence.Id.class);
// 获取特定参数对应的方法
Set<Method> someMethods = reflections.getMethodsMatchParams(long.class, int.class);
Set<Method> voidMethods = reflections.getMethodsReturn(void.class);
Set<Method> pathParamMethods =reflections.getMethodsWithAnyParamAnnotated(PathParam.class);
// 获取资源文件
Set<String> properties = reflections.getResources(Pattern.compile(".*\\.properties"));
标签:反射,Set,java,对应,获取,reflections,初探,注解,class 来源: https://www.cnblogs.com/ramese666/p/12841022.html