我无法在java反射中找到有关ConfigurationBuilder,FilterBuilder,Scanners的大量文档。有人可以解释一下我的用例是什么吗?
答案 0 :(得分:2)
您似乎在谈论来自Java Reflections library和不标准java.lang.reflect
代码的类。
为简单起见,所有三个类都用于配置Reflections对象,它将解析您的源代码并允许您查询它。
正如GitHub页面所述,有一些Javadoc:
如果你看一眼ConfigurationBuilder
javadoc,会出现一种模式(我自由地添加了一些注释以使事物发光):
new Reflections(
/*
* ConfigurationBuilder is used to build a configuration parsable by Reflection.
* This configuration must include a few things :
* - where to look for classes
* - what to look in classes
*/
new ConfigurationBuilder()
/*
* FilterBuilder answers the *where* question by specifying which fragments
* of classpath are to be scanned. Indeed, as far as I understand,
* Reflections can parse the whole classpath, which will be way to slow
* for anybody (and contains lots of useless java.* classes). So your
FilterBuilder defines include patterns for the packages you need
*/
.filterInputsBy(new FilterBuilder().include("your project's common package prefix here..."))
.setUrls(ClasspathHelper.forClassLoader())
/*
* Scanner defines the what : if you look for subclasses, you'll need
* to add a subclass scanner. if you look for
* annotations, the type annotation scanner is required, and so on.
*/
.setScanners(new SubTypesScanner(), new TypeAnnotationsScanner().filterResultsBy(myClassAnnotationsFilter)));
我想反思作者确实可以改善他们的文档......