我通过反射创建我的枚举,为此我向每个枚举添加一个实现抽象工厂的内部类。现在我想访问这个内部类以调用方法:
@Factory(FooFactory.class)
public enum Foo {
FOO, BAR;
public class FooFactory implements AbstractFactory<Foo> {
public Foo create(String value) {
return valueOf(value.toUpperCase());
}
}
}
@Factory
的定义是:
@Retention(RetentionPolicy.RUNTIME)
public @interface Factory {
Class<?> value();
}
然而,我收到以下错误:
Class cannot be resolved to a type FooFactory.java
当我尝试 @Factory(Foo$FooFactory.class)
时,我收到了错误:
The nested Foo$FooFactory cannot be referneced using its binary name.
那么甚至可以引用嵌套类吗?
最佳答案
从评论...显然
@Factory(Foo.FooFactory.class)
需要。
关于java - 用内部类注释类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12117132/