java - java反射中的ConfigurationBuilder、FilterBuilder、Scanners

标签 java reflection reflections

我在java反射中找不到太多关于ConfigurationBuilder、FilterBuilder、Scanners的文档。有人可以解释一下有什么用例吗?

最佳答案

您似乎在谈论 Java 中的类 Reflections library ,并且不是标准java.lang.reflect代码。

为了简单起见,所有三个类都用于配置 Reflections 对象,该对象将解析您的源代码并允许您查询它。

正如 GitHub 页面所述,有一些 Javadoc :

如果你看一眼ConfigurationBuilder javadoc,出现了一种模式(我自由地添加了一些注释以使事情变得 Shiny ):

  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)));

我想反射作者确实可以稍微改进他们的文档......

关于java - java反射中的ConfigurationBuilder、FilterBuilder、Scanners,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25384594/

相关文章:

java - Spring 启动 + LocalDate : "No primary or default constructor"

c# - 接口(interface)上的属性

c# - 我可以在接口(interface)方法中检索接口(interface)类型吗?

Java MethodHandlers.lookup().findStatic 抛出 NoSuchMethodException

java - AWS Lambda 和 Java 反射 (Guava)

java - 使用空间 O(边数)的图形表示的邻接列表

java - EAI经纪商模式

java - 我为什么要学习和使用struts?

c# - 使用反射(reflect)的类型 t 实例化类

java - 使用 Google 反射库检索项目中所有包的列表?