gpt4 book ai didi

java - 使用 Google Reflections 获取所有类的列表——但 java.* 似乎丢失了

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:18:13 24 4
gpt4 key购买 nike

我正在使用 google Reflections 包来构建可调用的所有类的索引。以下代码应该返回 JVM 中加载的所有类:

List<ClassLoader> classLoadersList = new LinkedList<ClassLoader>();
classLoadersList.add(ClasspathHelper.contextClassLoader());
classLoadersList.add(ClasspathHelper.staticClassLoader());
Reflections reflections = new Reflections(new ConfigurationBuilder()
.setScanners(new SubTypesScanner(false), new ResourcesScanner())
.setUrls(ClasspathHelper.forClassLoader(classLoadersList.toArray(new ClassLoader[0]))));
Set<Class<? extends Object>> allClasses =
reflections.getSubTypesOf(Object.class);

我注意到它返回的集合不包含 java.* 域中的任何内容。熟悉 Reflections 包的人可以告诉我如何获得这些吗?谢谢!

最佳答案

Google Reflections 可用于获取所有类,包括 java.*,尽管这不是它的主要用途。

Reflections reflections = new Reflections(
ClasspathHelper.forClass(Object.class),
new SubTypesScanner(false));

比:

Set<String> allClasses = 
reflections.getStore().getSubTypesOf(Object.class.getName());

关于java - 使用 Google Reflections 获取所有类的列表——但 java.* 似乎丢失了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14314789/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com