Java - 强制 class 实现接口以声明注释
Java - Force a class implementing an interface to declare an annotation
我试图强制 class SomeImpl 在实现接口 SomeInterface 时声明注释 @SomeAnnotation。解决方案可以修改SomeInterface声明。
public interface SomeInterface {}
public class SomeImpl implements SomeInterface -> compilation error
@SomeAnnotation
public class SomeInterfaceImpl implements SomeInterface -> compilation ok
用例:我在方法中使用实现 SomeInterface 的对象(不是我写的,它是一个外部库)总是读取注解@SomeAnnotation,它不能为空或默认。
谢谢!
我试图强制 class SomeImpl 在实现接口 SomeInterface 时声明注释 @SomeAnnotation。解决方案可以修改SomeInterface声明。
public interface SomeInterface {}
public class SomeImpl implements SomeInterface -> compilation error
@SomeAnnotation
public class SomeInterfaceImpl implements SomeInterface -> compilation ok
用例:我在方法中使用实现 SomeInterface 的对象(不是我写的,它是一个外部库)总是读取注解@SomeAnnotation,它不能为空或默认。
谢谢!