Can I generate a compile time error based on the type of the field being Annotated

后端 未结 2 579
忘了有多久
忘了有多久 2021-02-09 12:32

I have written a java annotation that looks like this:

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)  // can I further limit this to only fields         


        
2条回答
  •  难免孤独
    2021-02-09 12:57

    I believe that this is not enforcable at compile-time - If you want to ensure that it is not on any inappropriate fields, you would have to check at run/load-time.

提交回复
热议问题