简体   繁体   English

在Android上重复注释

[英]Repeating Annotations on Android

I want to make an annotation processor for my android projects. 我想为我的android项目制作一个注释处理器。

My annotations are simply like this 我的注释就像这样

@Author(name = "Jane Doe")
@Author(name = "John Smith")
class MyClass { ... }

But Repeating Annotations are supported as of the Java SE 8 Release and also android supports JDK 7 since API 19. 但是,从Java SE 8发行版开始,支持重复注释 ,并且自API 19起,android也支持JDK 7。

So Is there any way to use repeating annotations on android? 那么有没有办法在Android上使用重复注释?

现在有了Android N版本,支持重复注释

Edit 编辑

As @Saeed stated, this is now possible on Android N 正如@Saeed所说,现在可以在Android N上实现


Unfortunately you can't. 不幸的是你不能。 The only option I can think of would be to use something like: 我能想到的唯一选择是使用类似的东西:

@Author({ "Jane Doe", "John Smith"})
class MyClass { ... }

Or use other language highly compatible with android like Kotlin, which allows you to define @Repeatable annotations as you can see on the docs 或者使用与Kotlin高度兼容的其他语言,例如Kotlin,它允许您定义@Repeatable注释,如您在文档中看到的那样

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM