Java:“尚未实现”的通用注释

时间:2023-02-01 10:11:49

Is there a common or standard annotation in Java for methods that, while defined, have yet to be implemented?

Java中是否有一个通用或标准的注释用于定义尚未实现的方法?

So that, for instance, if I were using a pre-alpha version of a library that contained something like

因此,例如,如果我使用包含类似内容的库的pre-alpha版本

@NotImplementedYet
public void awesomeMethodThatTotallyDoesExactlyWhatYouNeed(){ /* TODO */ }

I'd get a compile-time warning when trying to call awesomeMethodThatTotallyDoesExactlyWhatYouNeed?

在尝试调用awesomeMethodThatTotallyDoesExactlyWhatYouNeed时,我会收到编译时警告?

3 个解决方案

#1


14  

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

您可能希望在运行测试时使用UnsupportedOperationException并检测对尚未实现的方法的调用。

#2


2  

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;
}

#3


0  

Google libraries use the @Beta annotations for API that is likely to change but the methods are implemented though

谷歌番石榴库使用@Beta注释API可能会改变,但方法已经实现

#1


14  

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

您可能希望在运行测试时使用UnsupportedOperationException并检测对尚未实现的方法的调用。

#2


2  

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;
}

#3


0  

Google libraries use the @Beta annotations for API that is likely to change but the methods are implemented though

谷歌番石榴库使用@Beta注释API可能会改变,但方法已经实现