创建自定义批注作为Framework-Annotation的别名? [英] Create custom Annotation as alias for Framework-Annotation?
本文介绍了创建自定义批注作为Framework-Annotation的别名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以创建自定义的Alias-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"};
}
这篇关于创建自定义批注作为Framework-Annotation的别名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文