创建自定义注释作为框架注释的别名? [英] Create custom Annotation as alias for Framework-Annotation?
本文介绍了创建自定义注释作为框架注释的别名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以创建自定义别名注释来代替
is it possible to create a custom Alias-Annotation to be used instead of
@SuppressWarnings("unused") // EventBus
public void onEvent(SomeMessage msg) { ... }
喜欢
@EventBusListener
public void onEvent(SomeMessage msg) { ... }
这将更加自我记录,当然应该包括 SuppressWarnings...对不起,如果这微不足道,但到目前为止我的谷歌搜索失败了.
This would be more self-documenting and should include the SuppressWarnings of course... Sorry if this trivial but my googling failed me so far.
推荐答案
您可以通过以下方式实现:
You can implement it following way :
@Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.CONSTRUCTOR, ElementType.LOCAL_VARIABLE})
@Retention(RetentionPolicy.SOURCE)
@SuppressWarnings("unused")
public @interface EventBusListener{
@AliasFor(annotation = SuppressWarnings.class, attribute = "value") String[] value() default {"unused"};
}
这篇关于创建自定义注释作为框架注释的别名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文