What's better to prevent the developer that my private method requires a notNull argument (Note that I am not using Spring framework)?
Use the @NotNull annotation
private void myBusinessMethod(@NotNull Object argument){ //... }
Which library I have to choose ?
javax.validation.constraints.NotNull
?Use the assertion
private void myBusinessMethod(Object argument){ assert argument != null ; //... }
throw an IllegalArgumentException
private void myBusinessMethod(Object argument){ if (argument == null){ throw new IllegalArgumentException ("Argument can't be null") ? } //... }
In the following link is recommended to use the assertions: http://www.javapractices.com/topic/TopicAction.do?Id=5
What do you think ?
Thank you