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() {
}
}
or
public class XImpl implements X {
@Override
public List<A> func() {
}
}
source
share