Is there a common or standard annotation in Java for methods that, while defined, have yet to be implemented?
So that, for instance, if I were using a pre-alpha version of a library that contained something like
@NotImplementedYet public void awesomeMethodThatTotallyDoesExactlyWhatYouNeed(){ /* TODO */ }
I'd get a compile-time warning when trying to call awesomeMethodThatTotallyDoesExactlyWhatYouNeed
?
@interface is used to create your own (custom) Java annotations. Annotations are defined in their own file, just like a Java class or interface. Here is custom Java annotation example: @interface MyAnnotation { String value(); String name(); int age(); String[] newNames(); }
Java annotations are marked with a @Target annotation to declare possible joinpoints which can be decorated by that annotation. Values TYPE , FIELD , METHOD , etc. of the ElementType enum are clear and simply understandable.
An annotation that has no method, is called marker annotation. For example: @interface MyAnnotation{}
Field Level Annotation Example. The annotation declares one String parameter with the name “key” and an empty string as the default value. When creating custom annotations with methods, we should be aware that these methods must have no parameters, and cannot throw an exception.
You might want to use UnsupportedOperationException and detect calls to-yet-to-be-implemented methods when running your tests.
You could create your own annotation. With the runtime retention policy you can then configure target builds to know to look for this annotation, if necessary.
import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Target({ ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) public @interface Unimplemented { boolean value() default true; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With