I am thinking to use @Nonnull
annotation provided in javax.annotaiton.Nonnull
which has retention policy as runtime. With this annotation I want to ensure that null is never returned by this function. I would like to put the annotation on interface so that no future implementations breaks existing code as follows
public interface X {
@Nonnull public List<A> func();
}
Now what I do not understand is that should I use the same annotation on the implementation as well. So which one of the following is would be the correct way to write the implementation of this interface (both of these compile):
public class XImpl implements X {
@Override
@Nonnull public List<A> func() {
//code
}
}
Or
public class XImpl implements X {
@Override
public List<A> func() {
//code
}
}