当前位置: 动力学知识库 > 问答 > 编程问答 >

java - Reflections returning 0 even though class clearly exists

问题描述:

I have a problem with reflections. I have a class that extends another class called ClassModel:

package net.gd.globalwars.commands;

public class Country extends CommandModel { }

And as you can see it is in package "net.gd.globalwars.commands"

Now I am using a new reflection object to find all classes that extend CommandModel and print the count, but the count is 0.

Reflections commands = new Reflections("net.gd.globalwars.commands");

System.err.println(commands.getSubTypesOf(CommandModel.class).size());

Thanks in advance!

网友答案:

Using this maven dependency, the code works as it should and returns 1:

<dependency>
     <groupId>org.reflections</groupId>
     <artifactId>reflections</artifactId>
     <version>0.9.9-RC1</version>
</dependency>

Assuming: Country, CommandModel, and the calling class are in the same package, though I doubt this makes a difference

分享给朋友:
您可能感兴趣的文章:
随机阅读: