[英]How can I disallow to use my own annotation for all classes instead of classes implementing concrete interface
我有以下代码。 我只需要允许对ICommand接口的classes-instances使用此批注(CommandName)。 我该怎么做?
@Retention(RetentionPolicy.RUNTIME) // Make this annotation accessible at runtime via reflection.
@Target({ElementType.TYPE}) // This annotation can only be applied to class methods.
public @interface CommandName {
String value();
}
在编译时,您不能这样做。 在运行时,只需检查类(由CommandName批注注释)即可,如果它们正在实现ICommand接口。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.