Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: Common Annotation for "Not Yet Implemented"

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?

like image 340
rampion Avatar asked Apr 02 '12 21:04

rampion


People also ask

What is @interface annotation in Java?

@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(); }

What is @target annotation in spring?

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.

What is the name of annotation that has no method?

An annotation that has no method, is called marker annotation. For example: @interface MyAnnotation{}

How are annotations implemented in Java?

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.


2 Answers

You might want to use UnsupportedOperationException and detect calls to-yet-to-be-implemented methods when running your tests.

like image 116
Alexander Avatar answered Sep 22 '22 21:09

Alexander


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; } 
like image 28
mhradek Avatar answered Sep 18 '22 21:09

mhradek