Iterate through values in @IntDef, @StringDef or any @Def class

我怕爱的太早我们不能终老 提交于 2019-12-04 05:07:52

I don't think you'll be able to query it like that at runtime. Your @MysterFlags annotation has a retention policy of SOURCE, which means it will be discarded by the compiler. Further, the @IntDef annotation has a retention policy of CLASS, which means it makes it through compile, but won't make it to runtime. That's why you are only seeing the @Retention annotation in your first loop (that annotation has a retention policy of RUNTIME).

Well, this might be a bit old now - but I had a similar problem and the solution that I've found was:

MysteryFlags.class.getDeclaredFields()

It will return all the definitions declared.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!