Does annotation need to be used for implementation when it is already specified in the interface

I am going to use the annotation @Nonnullpresented in javax.annotaiton.Nonnull, which has a retention policy as a runtime. With this annotation, I want this function to never return to null. I would like to put annotation on the interface so that no future implementations break existing code as follows

public interface X {
    @Nonnull public List<A> func();
}

Now I do not understand that I have to use the same annotation for implementation. So, which of the following options would be the right way to write an implementation of this interface (both of these compilations):

public class XImpl implements X {
    @Override
    @Nonnull public List<A> func() {
         //code
    }
}

or

public class XImpl implements X {
    @Override
    public List<A> func() {
         //code
    }
}
+4
source share
1 answer

. , javax.annotation.Nonnull (!). JSR 305, JSR 305 . JSR 305 .

, Checker Framework FindBugs. , , .

Checker Framework , , . , , .

FindBugs "inherit" "inheritance", . FindBugs , CheckReturnValue, , , , @. , , .

+3

Source: https://habr.com/ru/post/1568885/


All Articles