• <i id='xPPJR'><tr id='xPPJR'><dt id='xPPJR'><q id='xPPJR'><span id='xPPJR'><b id='xPPJR'><form id='xPPJR'><ins id='xPPJR'></ins><ul id='xPPJR'></ul><sub id='xPPJR'></sub></form><legend id='xPPJR'></legend><bdo id='xPPJR'><pre id='xPPJR'><center id='xPPJR'></center></pre></bdo></b><th id='xPPJR'></th></span></q></dt></tr></i><div id='xPPJR'><tfoot id='xPPJR'></tfoot><dl id='xPPJR'><fieldset id='xPPJR'></fieldset></dl></div>
      <bdo id='xPPJR'></bdo><ul id='xPPJR'></ul>
    <tfoot id='xPPJR'></tfoot>

    <legend id='xPPJR'><style id='xPPJR'><dir id='xPPJR'><q id='xPPJR'></q></dir></style></legend>
      1. <small id='xPPJR'></small><noframes id='xPPJR'>

        您可以使用反射找到包中的所有类吗?

        时间:2023-09-27

          <tfoot id='EZf0Z'></tfoot>
          <i id='EZf0Z'><tr id='EZf0Z'><dt id='EZf0Z'><q id='EZf0Z'><span id='EZf0Z'><b id='EZf0Z'><form id='EZf0Z'><ins id='EZf0Z'></ins><ul id='EZf0Z'></ul><sub id='EZf0Z'></sub></form><legend id='EZf0Z'></legend><bdo id='EZf0Z'><pre id='EZf0Z'><center id='EZf0Z'></center></pre></bdo></b><th id='EZf0Z'></th></span></q></dt></tr></i><div id='EZf0Z'><tfoot id='EZf0Z'></tfoot><dl id='EZf0Z'><fieldset id='EZf0Z'></fieldset></dl></div>
              <legend id='EZf0Z'><style id='EZf0Z'><dir id='EZf0Z'><q id='EZf0Z'></q></dir></style></legend>

                <bdo id='EZf0Z'></bdo><ul id='EZf0Z'></ul>

                  <tbody id='EZf0Z'></tbody>
              • <small id='EZf0Z'></small><noframes id='EZf0Z'>

                • 本文介绍了您可以使用反射找到包中的所有类吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  是否可以找到给定包中的所有类或接口?(快速查看例如 Package,好像没有.)

                  Is it possible to find all classes or interfaces in a given package? (Quickly looking at e.g. Package, it would seem like no.)

                  推荐答案

                  由于类加载器的动态特性,这是不可能的.类加载器不需要告诉虚拟机它可以提供哪些类,它们只是传递给类的请求,并且必须返回一个类或抛出一个异常.

                  Due to the dynamic nature of class loaders, this is not possible. Class loaders are not required to tell the VM which classes it can provide, instead they are just handed requests for classes, and have to return a class or throw an exception.

                  但是,如果您编写自己的类加载器,或检查类路径及其 jar,则可以找到这些信息.这将通过文件系统操作,而不是反射.甚至可能有一些库可以帮助您做到这一点.

                  However, if you write your own class loaders, or examine the classpaths and it's jars, it's possible to find this information. This will be via filesystem operations though, and not reflection. There might even be libraries that can help you do this.

                  如果有生成的类或远程交付的类,您将无法发现这些类.

                  If there are classes that get generated, or delivered remotely, you will not be able to discover those classes.

                  通常的方法是在某个文件中注册您需要访问的类,或者在不同的类中引用它们.或者只是在命名时使用约定.

                  The normal method is instead to somewhere register the classes you need access to in a file, or reference them in a different class. Or just use convention when it comes to naming.

                  附录:反射库将允许您在当前类路径中查找类.它可用于获取包中的所有类:

                  Addendum: The Reflections Library will allow you to look up classes in the current classpath. It can be used to get all classes in a package:

                   Reflections reflections = new Reflections("my.project.prefix");
                  
                   Set<Class<? extends Object>> allClasses = 
                       reflections.getSubTypesOf(Object.class);
                  

                  这篇关于您可以使用反射找到包中的所有类吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:build文件夹下的文件已生成,不应编辑,无法重新 下一篇:Java包名称中单词分隔符的约定是什么?

                  相关文章

                  最新文章

                  1. <tfoot id='HqIbd'></tfoot>
                      <bdo id='HqIbd'></bdo><ul id='HqIbd'></ul>
                    <i id='HqIbd'><tr id='HqIbd'><dt id='HqIbd'><q id='HqIbd'><span id='HqIbd'><b id='HqIbd'><form id='HqIbd'><ins id='HqIbd'></ins><ul id='HqIbd'></ul><sub id='HqIbd'></sub></form><legend id='HqIbd'></legend><bdo id='HqIbd'><pre id='HqIbd'><center id='HqIbd'></center></pre></bdo></b><th id='HqIbd'></th></span></q></dt></tr></i><div id='HqIbd'><tfoot id='HqIbd'></tfoot><dl id='HqIbd'><fieldset id='HqIbd'></fieldset></dl></div>

                    <legend id='HqIbd'><style id='HqIbd'><dir id='HqIbd'><q id='HqIbd'></q></dir></style></legend>

                    <small id='HqIbd'></small><noframes id='HqIbd'>