i would like to know if there is some good way in java to show that some method should never be invoked? I'm thinking in case that I work with bigger team, and to tell guys that this method will never be invoked, so don't try to test it. Maybe assert is a good idea?
Context: i'm using ReactiveX in java and my Observable will never be stopped, it can only invoke onError and onNext, but onCompleted will never be invoked, but my Observer extends Subscriber so i need to @Override onCompleted.
@Deprecated
is the closest standard thing, and throwing UnsupportedOperationException
is a reasonable thing to do in many similar cases.
Note also that due to polymorphism, the caller may well not know the concrete type of the Observer
they are calling until runtime, so no annotation could help.
However, in the case you've described, I think you should write an empty implementation of onCompleted()
and a test that just asserts that it doesn't throw an exception. Although you've decided that the Observable will never stop producing, it doesn't seem reasonable to throw an exception if one day it does.