Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Annotating Unstable Classes/Methods for Javadoc

Tags:

java

javadoc

When developing new classes/methods for a Java project, you sometimes want to let people try out your new code but don't want to guarantee it will be backwards-compatible in future versions. In this situation it would make sense to have something like an @Unstable annotation to notify users that this code will not have backwards compatibility guarantees until it stabilizes (an @Unstable feature is different from a @Deprecated feature in that it may be changed or removed without being considered a breaking change). It would also be necessary for such annotations to be reflected in the javadoc-generated HTML so that the user is aware of them. Being very optimistic, it would also be helpful for there to be a compiler warning if you are using code that is annotated @Unstable.

Is there any standard for such a feature in Java? If not, is there a way to customize javadoc to allow for such a feature?

like image 748
Iceberg Avatar asked Sep 13 '15 23:09

Iceberg


People also ask

Can Java annotations have methods?

An annotation is a construct associated with Java source code elements such as classes, methods, and variables.

What is annotated method?

Annotations are used to provide supplemental information about a program. Annotations start with '@'. Annotations do not change the action of a compiled program. Annotations help to associate metadata (information) to the program elements i.e. instance variables, constructors, methods, classes, etc.

How do you declare annotations in Java?

Annotation is defined like a ordinary Java interface, but with an '@' preceding the interface keyword (i.e., @interface ). You can declare methods inside an annotation definition (just like declaring abstract method inside an interface). These methods are called elements instead.

What are marker annotations in Java?

What is a Marker Annotation? Marker annotations are special annotations in Java that do not contain any members or data. As marker interfaces do not contain any members, just declaring the annotation in your code is sufficient for it to influence the output in whatever terms you want.


1 Answers

No, there is no standard for such a feature in Java.

To add this information to the generated Javadoc you can use @Documented on your own annotation.

import java.lang.annotation.Documented;

@Documented
public @interface Unstable {
}

With this the annotation will appear in the Javadoc of the annotated type, field, method, etc.

public interface AlwaysChangingApi {
    @Unstable
    String process(String someParameter);
}
like image 135
Florian Genser Avatar answered Sep 29 '22 03:09

Florian Genser