Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我尝试使用反射来获取在 java 中实现给定接口的每个类,仅使用 java.lang.reflect 中的类。由于许多原因,我不能使用任何外部库。
我发现很多教程可以用 java.lang.reflect 做很多事情,但没有任何东西可以让每个类都实现给定接口。任何想法?
如果存在这样的方法,则需要预先加载 Classpath 中的所有类,因为您怎么知道哪些类实现了该接口?这肯定会消耗性能,并且与常见的 JVM 设计背道而驰。
所以,对不起,但我怀疑你会找到一种方法来做到这一点,而无需更复杂的方法。